![a0b125a01e6a69a19d6e00ff97b1fe53.png](https://i-blog.csdnimg.cn/blog_migrate/56cd78494f7094624a3f20a8af4ace60.jpeg)
首先导入需要Python。
import numpy as npimport pandas as pdfrom sklearn.metrics import accuracy_scorefrom sklearn.model_selection import train_test_splitfrom sklearn.model_selection import cross_val_score, GridSearchCVfrom sklearn.linear_model import LogisticRegressionfrom sklearn.tree import DecisionTreeClassifierfrom sklearn.ensemble import RandomForestClassifierpd.set_option('display.max_columns', None) # Unlimited columns.pd.options.mode.use_inf_as_na = True # Any inf or -inf is # treated as NA.
![57867191b660e7daca800e39a8e861b2.png](https://i-blog.csdnimg.cn/blog_migrate/55d26e05e91b038ce76254eb9a0ac1ee.jpeg)
读取训练特征数据(此机器学习数据集下载地址在文末):
X_train_original = pd.read_csv('./train_features.csv', header = [0], # Top row is header. index_col = 0) # First col is index.X_train_original.head()
![671245de0572a07f3964cf4b14f0cf68.png](https://i-blog.csdnimg.cn/blog_migrate/1984174467eac95f2b03d7d8a99e2911.jpeg)
![9f19f3158bef2a462bff51a1267868f8.png](https://i-blog.csdnimg.cn/blog_migrate/0f1171157fd45f5e2c93223b19e66f46.jpeg)
读取训练目标数据:
y_train_original = pd.read_csv('./train_labels.csv', header = [0], # Top row is header. index_col = 0) # First col is index.y_train_original.head()
![6c514684b77ba09cb8765ed286b54532.png](https://i-blog.csdnimg.cn/blog_migrate/58a5c723b97654fef3d9cc8f786a5113.jpeg)