thedenisnikulin

Untitled

Apr 10th, 2020
864
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. import csv
  2. import numpy
  3. import matplotlib.pyplot as plt
  4.  
  5. from sklearn.model_selection import train_test_split
  6. from sklearn.linear_model import LinearRegression
  7. from sklearn import preprocessing
  8.  
  9. # prepare data
  10. with open('coefs', newline='') as csvfile:
  11.     target = list(csv.reader(csvfile))
  12.     target = [float(target[t][0]) for t in range(len(target))]
  13.     target = numpy.array(target)
  14.  
  15. with open('users_cash', newline='') as csvfile:
  16.     data = list(csv.reader(csvfile))
  17.     for d in range(len(data)):
  18.         for nested_d in range(len(data[d])):
  19.             data[d][nested_d] = int(float(data[d][nested_d]))
  20.     data = numpy.array(data)
  21.    
  22.  
  23. X_train, X_test, y_train, y_test = train_test_split(data, target, random_state=0)
  24. yy = preprocessing.LabelEncoder().fit_transform(y_train)
  25. knn = LinearRegression()
  26. knn.fit(X_train, yy)
  27.  
  28. # X_new = numpy.array([input('users: '), input('cash: ')])
  29.  
  30. y_pred = knn.predict(X_test)
  31. print(y_pred)
  32. print(y_test)
  33. print(X_test)
  34. print('правильность: {:.2f}'.format(numpy.mean(y_pred == y_test)))
Advertisement
Add Comment
Please, Sign In to add comment