Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. # Vaš kôd ovdje
  2. X = make_instances(-5,5,1000)
  3. x_train500, x_test500 = model_selection.train_test_split(X, test_size=0.5)
  4.  
  5. x_train167, x_train333 = model_selection.train_test_split(x_train500, test_size=2/3)
  6. x_test167, x_test333 = model_selection.train_test_split(x_test500, test_size=2/3)
  7.  
  8.  
  9. #############################################
  10.  
  11. y_train167_1 = list(make_labels(x_train167, f, 100))
  12. y_train167_2 = list(make_labels(x_train167, f, 200))
  13. y_train167_5 = list(make_labels(x_train167, f, 500))
  14.  
  15. y_train333_1 = list(make_labels(x_train333, f, 100))
  16. y_train333_2 = list(make_labels(x_train333, f, 200))
  17. y_train333_5 = list(make_labels(x_train333, f, 500))
  18.  
  19. y_train500_1 = list(make_labels(x_train500, f, 100))
  20. y_train500_2 = list(make_labels(x_train500, f, 200))
  21. y_train500_5 = list(make_labels(x_train500, f, 500))
  22.  
  23. ##############################################
  24.  
  25. y_test167_1 = list(make_labels(x_test167, f, 100))
  26. y_test167_2 = list(make_labels(x_test167, f, 200))
  27. y_test167_5 = list(make_labels(x_test167, f, 500))
  28.  
  29. y_test333_1 = list(make_labels(x_test333, f, 100))
  30. y_test333_2 = list(make_labels(x_test333, f, 200))
  31. y_test333_5 = list(make_labels(x_test333, f, 500))
  32.  
  33. y_test500_1 = list(make_labels(x_test500, f, 100))
  34. y_test500_2 = list(make_labels(x_test500, f, 200))
  35. y_test500_5 = list(make_labels(x_test500, f, 500))
  36.  
  37. ##############################################
  38.  
  39. x_train_all = [x_train167, x_train333, x_train500]
  40. y_train_all = [y_train167_1,y_train167_2,y_train167_5,
  41. y_train333_1,y_train333_2,y_train333_5,
  42. y_train500_1,y_train500_2,y_train500_5]
  43.  
  44. x_test_all = [x_test167, x_test333, x_test500]
  45. y_test_all = [y_test167_1,y_test167_2,y_test167_5,
  46. y_test333_1,y_test333_2,y_test333_5,
  47. y_test500_1,y_test500_2,y_test500_5]
  48.  
  49. ##############################################
  50.  
  51. D = range(1,21)
  52.  
  53. _, plots = plt.subplots(3,3)
  54.  
  55. for i in range(0,9):
  56. E_train=[]
  57. E_test=[]
  58. i_=[]
  59. if i<3:
  60. j=0
  61. elif i<6:
  62. j=1
  63. else:
  64. j=2
  65. for d in D:
  66. i_.append(i)
  67. poly=preprocessing.PolynomialFeatures(d)
  68. fi_train = poly.fit_transform(x_train_all[j])
  69. fi_test = poly.fit_transform(x_test_all[j])
  70.  
  71. regr_train = LinearRegression().fit(fi_train,y_train_all[i])
  72.  
  73. y_pred_train = regr_train.predict(fi_train)
  74. y_pred_test = regr_train.predict(fi_test)
  75.  
  76. E = mean_squared_error(y_train_all[i], y_pred_train)
  77. E_train.append(E)
  78. E = mean_squared_error(y_test_all[i], y_pred_test)
  79. E_test.append(E)
  80.  
  81. plots[i//3][i%3].plot(D, np.log(E_train), label = 'train')
  82. plots[i//3][i%3].plot(D, np.log(E_test), label = 'test')
  83.  
  84. plots[i//3][i%3].legend(loc='best')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement