Let’s do this problem today
The process to solve the problem.
Let’s start with the packages and processes to use
It’s the same thing as linear regression
Import data import pandas as PDpandas Imports data
Then visualize from matplotlib import Pyplot as PLT
Linear_model import LogisticRegression this time is not linear regression, so use LogisticRegression
Import numpy as NP to construct the data to be predicted
The evaluation model from sklear. metrics import accuracy_score is still evaluated as before
Right? Most of them are the same
So let’s just cut to the code.
import numpy as np import pandas as pd from matplotlib import pyplot as plt from sklearn.linear_model import Metrics import accuracy_score = pd.read_csv('task1_data.csv') Figure () plt.figure() plt.loc [:, 'size 1'], data.loc[:, 'size2']) plt.title('chip size1-size2') plt.xlabel('size1') plt.ylabel('size2') # plt.show() # create a variable to filter good and bad products mask mask = Loc [:, 'y'] == 1 print(mask) fig2 = plt.figure() OK = plt.loc [:, 'size 1'][mask], data.loc[:,' size 1'] == 1 print(mask) fig2 = plt.figure() OK = plt.loc [:, 'size 1'][mask], data.loc[:, '2' size] [mask]) ng = PLT. Scatter (data. The loc [: '1' size] [~ mask], data. The loc [:, [~mask]) plt.title('chip size1-size2') plt.xLabel ('size1') plt.yLabel ('size2') plt.legend((ok, ng), ('ok', 'ng')) PLT. The show () # x, x = y assignment data. The drop ([' y '], axis = 1) y = data. The loc [:, Model = LogisticRegression() model.fit(x, x, x) Print (y) print(y_predict) accuracy = accuracy_score(y, accuracy_predict) Y_predict) print(accuracy) # x_test = np.array([[1, 10]]) y_test_predict = model.predict(x_test) print(y_test_predict) print('ok' if y_test_predict==1 else 'ng') print(model.intercept_) print(model.coef_) theta0 = model.intercept_[0] theta1, theta2 = model.coef_[0][0], Model. Coef_ [0][1] print(theta0, theta1, theta2) x1 = data.loc[:, 'size 1'] x2_new = -(theta0 + theta1*x1)/theta2 # Figure 3 = plt.figure() plt.loc [:, 'size 1'], data.loc[:, Plt.title ('chip size1-size2') plt.xLabel ('size1') plt.yLabel ('size2') OK = plt.loc [:, '1' size] [mask], data. The loc [:, '2' size] [mask]) ng = PLT. Scatter (data. The loc [: '1' size] [~ mask], data. The loc [:, [~mask]) plt.title('chip size1-size2') plt.plot(x1, x1) x2_new) plt.xlabel('size1') plt.ylabel('size2') plt.legend((ok, ng), ('ok', 'ng')) plt.show()Copy the code