Mooplab(新網銀行杯)

2020-10-25 10:01:05

Mooplab(新網銀行杯)

一、pycharm第三方庫安裝不上的問題(2020.10.19-10.21)

相關方法:

  1. 在終端上安裝包
    1. win+R
    2. 輸入cmd進入終端
    3. pip install (numpy)‘要裝的安裝包’ -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
  2. 更新pip:終端輸入python -m pip install --upgrade pip
  3. PyCharm安裝教學(Windows):https://www.runoob.com/w3cnote/pycharm-windows-install.html

二、‘mbcs’ codec can’t encode characters in position 0–1: invalid character 問題(2020.10.22)

方法:

  1. 原因:路徑問題,將字串作為路徑直接使用,需要跳脫

    出錯程式碼:pd.read_csv(‘duringopereation\patients\patients_csv\23483949.csv’, encoding = 「gb2312」)

    修改程式碼:pd.read_csv(‘duringopereation\patients\patients_csv\23483949.csv’, encoding = 「gb2312」)

  2. 將路徑刪掉重新手敲一遍解決(之前是檔案屬性裡複製的路徑)

解決方案:

  • 用第二個方案解決

三、KNN&SVM(分類方法) (2020.10.22)

import pandas as pd
import numpy as np
from sklearn.neighbors import KNeighborsClassifier

# 讀取資料
dfx_train = pd.read_csv(r"E:/新網銀行杯/data_b_train.csv")
dfx_test = pd.read_csv(r"E:/新網銀行杯/data_b_test.csv")
dfy_train = pd.read_csv(r"E:/新網銀行杯/y_train.csv")
print(dfx_train)

# 字典中的key轉換為列表
key_value = list(dfx_train.keys())
print('字典中的key轉換為列表:', key_value)
x1_train = np.array(list(dfx_train['x_num_0']))
# x2_train = np.array(list(dfx_train['x_num_1']))
x3_train = np.array(list(dfx_train['x_num_2']))
# x4_train = np.array(list(dfx_train['x_num_3']))
# x5_train = np.array(list(dfx_train['x_num_4']))
# x6_train = np.array(list(dfx_train['x_num_5']))
# x7_train = np.array(list(dfx_train['x_num_6']))
# x8_train = np.array(list(dfx_train['x_num_7']))

x_train=np.array([x1_train,x3_train])
x_train=x_train.T
y_train  = np.array(list(dfy_train['target']))
y_train=y_train.T

#
x1_test = np.array(list(dfx_test['x_num_0']))
# x2_test = np.array(list(dfx_test['x_num_1']))
x3_test = np.array(list(dfx_test['x_num_2']))
# x4_test = np.array(list(dfx_test['x_num_3']))
# x5_test = np.array(list(dfx_test['x_num_4']))
x_test=np.array([x1_test,x3_test])
x_test=x_test.T

#==================================
# KNN
#==================================
knn = KNeighborsClassifier()
knn.fit(x_train,y_train)
y_test=knn.predict(x_test)
print(len(y_test))
#==================================
# SVM
#==================================
# from sklearn.svm import SVC
# model = SVC(kernel='rbf', probability=True)#probability=False時,沒辦法呼叫 model.predict_proba()函數
# model.fit(x_train,y_train)
# pre = model.predict_proba(C)
# print(pre)
# y_test = model.predict(x_test)
# print(y_test)

#==================================
# 匯出
#==================================
data_df = pd.DataFrame(y_test)

# change the index and column name
data_df.columns = ['target']
data_df.index = list(range(0,5767))

# create and writer pd.DataFrame to excel
writer = pd.ExcelWriter('E:/新網銀行杯/y_test.xlsx')
data_df.to_excel(writer,'page_1',float_format='%.5f') # float_format 控制精度
writer.save()

四、隨機生成數(2020.10.22)

import numpy as np
import pandas as pd
import random
a=[]
for i in range(1,5767):
    a.append(random.randint(0,1))

a = np.array(a)
# prepare for data
data = a.reshape((5766,1))
print(data)
data_df = pd.DataFrame(data)

# change the index and column name
data_df.columns = ['target']
data_df.index = list(range(1,5767))

# create and writer pd.DataFrame to excel
writer = pd.ExcelWriter('Save_Excel.xlsx')
data_df.to_excel(writer,'page_1',float_format='%.5f') # float_format 控制精度
writer.save()

五、基礎理論(2020.10.23)

建模

  1. read讀資料 (讀入scv.檔案)
  2. operation 操作(pre-processing [用pandas])
  3. modeling建模
  4. result得出結果
  5. write寫論文

六、第二次開會(2020.10.23)

任務:

  1. 資料預處理(-99用取均值的方法)
  2. 感知機分類
  3. 篩選資料(可手動刪除部分資訊)
  4. 行為資訊資料(給時間點加權)
#pnn感知器分類
from sklearn.linear_model import Perceptron
ppn = Perceptron()
ppn.fit(x_train, y_train)
y_test = ppn.predict(x_test)

學習目標:

python:

  1. 語法
  2. numpy
  3. pandas