Documente Academic
Documente Profesional
Documente Cultură
import numpy as np
rng = np.random.RandomState(1)
y = np.sin(X).ravel()
regr_1 = DecisionTreeRegressor(max_depth=2)
regr_2 = DecisionTreeRegressor(max_depth=5)
regr_1.fit(X, y)
regr_2.fit(X, y)
# Predict
y_1 = regr_1.predict(X_test)
y_2 = regr_2.predict(X_test)
plt.figure()
c="darkorange", label="data")
plt.plot(X_test, y_1, color="cornflowerblue",
label="max_depth=2", linewidth=2)
plt.xlabel("data")
plt.ylabel("target")
plt.legend()
plt.show()
SVM
import numpy as np
X, Y = make_blobs(n_samples=500, centers=2,
random_state=0, cluster_std=0.40)
# plotting scatters
plt.show()
#creating line space between -1 to 3.5
# plotting scatter
for m, b, d in [(1, 0.65, 0.33), (0.5, 1.6, 0.55), (-0.2, 2.9, 0.2)]:
yfit = m * xfit + b
color='#AAAAAA', alpha=0.4)
plt.xlim(-1, 3.5);
plt.show()
import numpy as np
# number of observations/points
n = np.size(x)
return(b_0, b_1)
# putting labels
plt.xlabel('x')
plt.ylabel('y')
# function to show plot
plt.show()
def main():
# observations
x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
# estimating coefficients
b = estimate_coef(x, y)
plot_regression_line(x, y, b)
if _name_ == "_main_":
main()
LINEAR REGRESSION
import numpy as np
# number of observations/points
n = np.size(x)
# mean of x and y vector
return(b_0, b_1)
plt.xlabel('x')
plt.ylabel('y')
plt.show()
def main():
# observations
x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
# estimating coefficients
b = estimate_coef(x, y)
plot_regression_line(x, y, b)
if _name_ == "_main_":
main()
--