Mooplab (Xinwang Bank Cup)

Mooplab (Xinwang Bank Cup)

1. The problem that pycharm third-party libraries cannot be installed (2020.10.19-10.21)

Related methods:

  1. Install the package on the terminal
    1. win+R
    2. Enter cmd into the terminal
    3. pip install (numpy)'installation package to be installed' -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
  2. Update pip: terminal type python -m pip install --upgrade pip
  3. PyCharm installation tutorial (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)

method:

  1. Reason: path problem, use string directly as path, need to escape

    Error code: pd.read_csv('duringopereation\patients\patients_csv\23483949.csv', encoding = "gb2312")

    Modify the code: pd.read_csv('duringopereation\patients\patients_csv\23483949.csv', encoding = "gb2312")

  2. Delete the path and re-click to solve it (previously the path copied in the file properties)

solution:

  • Solve with the second solution

3. KNN&SVM (classification method) (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()

4. Randomly generated numbers (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()

5. Basic theory (2020.10.23)

Modeling

  1. read read data (read into scv. file)
  2. operation (pre-processing [using pandas])
  3. modeling
  4. result
  5. write

6. The second meeting (2020.10.23)

task:

  1. Data preprocessing (-99 uses the average method)
  2. Perceptron classification
  3. Filter data (some information can be deleted manually)
  4. Behavioral information data (weighting time points)
#pnn感知器分类
from sklearn.linear_model import Perceptron
ppn = Perceptron()
ppn.fit(x_train, y_train)
y_test = ppn.predict(x_test)

learning target:

python:

  1. grammar
  2. numpy
  3. pandas

Guess you like

Origin blog.csdn.net/Zhang_lanxi/article/details/109249525