資源簡介
python數據挖掘-電力竊漏電用戶自動識別,書上的源碼有錯誤,現已經完全改正。

代碼片段和文件信息
#-*-?coding:?utf-8?-*-
#拉格朗日插值代碼
import?pandas?as?pd?#導入數據分析庫Pandas
from?scipy.interpolate?import?lagrange?#導入拉格朗日插值函數
inputfile?=?‘../data/missing_data.xls‘?#輸入數據路徑需要使用Excel格式;
outputfile?=?‘../tmp/missing_data_processed.xls‘?#輸出數據路徑需要使用Excel格式
data?=?pd.read_excel(inputfile?header=None)?#讀入數據
#自定義列向量插值函數
#s為列向量,n為被插值的位置,k為取前后的數據個數,默認為5
def?ployinterp_column(s?n?k=5):
??y?=?s[list(range(n-k?n))?+?list(range(n+1?n+1+k))]?#取數
??y?=?y[y.notnull()]?#剔除空值
??return?lagrange(y.index?list(y))(n)?#插值并返回插值結果
#逐個元素判斷是否需要插值
for?i?in?data.columns:
??for?j?in?range(len(data)):
????if?(data[i].isnull())[j]:?#如果為空即插值。
??????data[i][j]?=?ployinterp_column(data[i]?j)
data.to_excel(outputfile?header=None?index=False)?#輸出結果
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-01-03?11:11??chapter6\
?????目錄???????????0??2018-01-03?10:35??chapter6\demo\
?????目錄???????????0??2018-01-03?10:48??chapter6\demo\code\
?????文件????????1011??2015-12-05?21:05??chapter6\demo\code\6-1_Lagrange_interpolation.py
?????文件????????1611??2018-01-03?10:47??chapter6\demo\code\6-2_dt_model.py
?????文件????????2147??2016-11-28?11:15??chapter6\demo\code\6-3_lm_model.py
?????文件?????????571??2018-01-03?10:48??chapter6\demo\code\cm_plot.py
?????目錄???????????0??2018-01-03?10:41??chapter6\demo\code\__pycache__\
?????文件?????????657??2018-01-03?10:41??chapter6\demo\code\__pycache__\cm_plot.cpython-36.pyc
?????目錄???????????0??2018-01-03?10:35??chapter6\demo\data\
?????文件???????25088??2015-12-05?21:05??chapter6\demo\data\missing_data.xls
?????文件???????40448??2015-12-05?21:05??chapter6\demo\data\model.xls
?????目錄???????????0??2018-01-03?10:35??chapter6\demo\tmp\
?????文件????????5632??2018-01-03?10:38??chapter6\demo\tmp\missing_data_processed.xls
?????文件????????8296??2015-12-05?21:05??chapter6\demo\tmp\net.model
?????文件????????3803??2018-01-03?10:47??chapter6\demo\tmp\tree.pkl
?????文件??????????84??2015-12-05?21:05??chapter6\demo\tmp\tree.pkl_01.npy
?????文件?????????800??2015-12-05?21:05??chapter6\demo\tmp\tree.pkl_02.npy
?????文件????????2432??2015-12-05?21:05??chapter6\demo\tmp\tree.pkl_03.npy
?????文件??????????96??2015-12-05?21:05??chapter6\demo\tmp\tree.pkl_04.npy
?????目錄???????????0??2018-01-03?10:35??chapter6\test\
?????目錄???????????0??2018-01-06?11:48??chapter6\test\code\
?????文件?????????622??2018-01-05?14:07??chapter6\test\code\cm_plot.py
?????文件????????1994??2018-01-06?11:04??chapter6\test\code\dt_model.py
?????文件????????1011??2015-12-05?21:05??chapter6\test\code\Lagrange_interpolation.py
?????文件????????2572??2018-01-05?21:21??chapter6\test\code\lm_model.py
?????文件????????3010??2018-01-06?11:48??chapter6\test\code\Mix-lm-dt_model.py
?????目錄???????????0??2018-01-05?21:20??chapter6\test\code\__pycache__\
?????文件?????????655??2018-01-05?17:48??chapter6\test\code\__pycache__\cm_plot.cpython-36.pyc
?????文件????????1494??2018-01-05?21:20??chapter6\test\code\__pycache__\dt_model.cpython-36.pyc
?????目錄???????????0??2018-01-05?14:39??chapter6\test\data\
............此處省略8個文件信息
評論
共有 條評論