import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
data = pd.read_csv('chip_test.csv')
data.head()
首先导包,读取数据这些基础操作就不说了,接着就是可视化展示,分析数据特征
mask = data.loc[:,'pass'] == 1
fig2 = plt.figure(figsize=(10,8))
failed = plt.scatter(data.loc[:,'test1'][mask],data.loc[:,'test2'][mask])
passed = plt.scatter(data.loc[:,'test1'][~mask],data.loc[:,'test2'][~mask])
plt.xlabel('test1')
plt.ylabel('test2')
plt.title('logisitic')
plt.legend((passed,failed),('passed','failed'))
plt.show()
x = data.drop(['pass'],axis=1)
y = data.loc[:,'pass']
x1 = data.loc[:,'test1']
x2 = data.loc[:,'test2']
x1_2 = x1*x1
x2_2 = x2*x2
x1x2 = x1*x2
a = {'x1':x1,'x2':x2,'x1_2':x1_2,'x2_2':x2_2,'x1x2':x1x2}
data_new = pd.DataFrame(a)
data_new.head()
from sklearn.linear_model import LogisticRegression
lr1 = LogisticRegression()
lr1.fit(data_new,y)
y1_predict = lr1.predict(data_new)
print(accuracy_score(y,y1_predict))
可以发现模型评分为81左右,并不是很高,这里我只是做一个简单的运用,当然你也可以用更复杂的模型,甚至在训练集上可以达到100%正确率,但会导致模型过拟合,没有更好的泛化能力,所以根据自己的需求来衡量