from matplotlib import pyplot as plt from sklearn import metrics from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split from sklearn.preprocessing import PolynomialFeatures from sklearn.pipeline import Pipeline import pandas as pd def start(): data = pd.read_csv('loan.csv') x = data[['ApplicantIncome', 'Credit_History', 'Education', 'Married', 'Self_Employed']] y = data[['LoanAmount']] x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.1, random_state=42) poly = Pipeline([('poly', PolynomialFeatures(degree=3)), ('linear', LinearRegression())]) poly.fit(x_train, y_train) y_predicted = poly.predict(x_test) print('Оценка обучения:') print(metrics.r2_score(y_test, y_predicted)) plt.figure(1, figsize=(16, 9)) plt.title('Сравнение результатов обучения') plt.scatter(x=[i for i in range(len(x_test))], y=y_test, c='green', s=5) plt.scatter(x=[i for i in range(len(x_test))], y=y_predicted, c='red', s=5) plt.show() start()