import sys import matplotlib.pyplot as plt import pandas as pd from mylinearregression import MyLR data = pd.read_csv("./resources/spacecraft_data.csv") X = np.array(data[["Age", "Thrust_power", "Terameters"]]) Y = np.array(data[["Sell_price"]]) theta = np.array([[1.], [1.], [1.], [1.]]) mylr_ne = MyLR(theta) mylr_lgd = MyLR(theta) Y_pred = mylr_ne.predict_(X) ############### Gradient descente ############ print("Basic cost = " + str(mylr_lgd.mse_(X, Y))) mylr_lgd.fit_(X, Y, alpha=5e-5, n_cycle=10000) print("Cost after gradient descente = " + str(mylr_lgd.mse_(X, Y))) print("Theta after gradient descente = " + str(mylr_lgd.theta)) Y_grad = mylr_lgd.predict_(X) ############################################## #print() ############# Normale Equation ############### mylr_ne.normalequation_(X, Y) print("Cost after Normale equation = " + str(mylr_ne.mse_(X, Y))) print("Theta after normale equation = " + str(mylr_ne.theta)) Y_ne = mylr_ne.predict_(X) ##############################################
# +#+#+#+#+#+ +#+ # # Created: 2020/02/10 12:22:13 by ythomas #+# #+# # # Updated: 2020/02/10 15:13:21 by ythomas ### ########.fr # # # # **************************************************************************** # import numpy as np from mylinearregression import MyLR import sys import matplotlib.pyplot as plt import pandas as pd data = pd.read_csv("./resources/are_blue_pills_magics.csv") Xpill = np.array(data["Micrograms"]).reshape(-1, 1) Yscore = np.array(data["Score"]).reshape(-1, 1) theta1 = np.array([[89.0], [-8]]) theta2 = np.array([[89.0], [-6]]) mylm1 = MyLR(theta1) mylm2 = MyLR(theta2) print(Xpill) print("========") print(Yscore) Y_lm1 = mylm1.predict_(Xpill) plt.plot(Xpill, Yscore, 'g^') y = Xpill * theta1[1] + theta1[0] plt.plot(Xpill, y) plt.grid(True) plt.show() print(mylm1.mse_(Xpill, Yscore)) print(mylm2.mse_(Xpill, Yscore))