lr = LinearRegression(X, y, tolerance=1e-4) lr.newton_general() print('LinearRegression, theta of newton_general: ', lr.theta.T, ', num of iterations: ', len(lr.loss_history)) show_result(lr, "Method: newton_general") # invoke newton with Armijo search method lr = LinearRegression(X, y, tolerance=1e-4) lr.newton_armijo() print('LinearRegression, theta of newton_armijo: ', lr.theta.T, ', num of iterations: ', len(lr.loss_history)) show_result(lr, "Method: newton_armijo") # local weight linear regression taus = np.linspace(1, 0, 5, False) for tau in np.nditer(taus): _, y_estimate = lr.fit_local_weight_lr(X, tau) plt.title("local weight linear regression with tau=" + str(tau)) plt.plot(lr.features[:, :-1], lr.labels, 'bo') plt.plot(X, y_estimate, 'r-') plt.show() # Test fot Logistic Regression # load data data = pd.read_csv("./apple_juice.dat", header=None, sep=r"\s+") data = data.as_matrix() X = data[:, 0: -1] y = data[:, -1] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) # create Logistic Regression model lr = LogisticRegression(X_train, y_train, tolerance=1e-5)