Ml programs

By: Anonymous1/23/202613 views Public Note
ML Program 1 import numpy as np import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression X=np.array([1,2,3,4,5]).reshape(-1,1) Y=np.array([2,4,5,4,5]) model=LinearRegression() model.fit(X,Y) slope=model.coef_[0] intercept=model.intercept_ print(f"Slope:{slope:2f}") print(f"intercept:{intercept:2f}") y_pred=model.predict([[6]]) print(f"Prediction for x=6:{y_pred[0]:.2f}") plt.scatter(X,Y,color="blue",label="Data") plt.plot(X,model.predict(X),color="red",label="Regression Line") plt.legend() plt.show() 2.ml program import numpy as np import matplotlib.pyplot as plt import pandas as pd from sklearn.linear_model import LinearRegression dataset_path = "employee_salary_dataset.csv" data = pd.read_csv(dataset_path) x = data["Experience_Years"].values.reshape(-1, 1) y = data["Monthly_Salary"].values model = LinearRegression() model.fit(x, y) slope = model.coef_[0] intercept = model.intercept_ print(f"slope: {slope:.2f}") print(f"intercept: {intercept:.2f}") y_pred = model.predict([[8]]) print(f"prediction for x=8 (Experience_Years): {y_pred[0]:.2f}") plt.scatter(x, y, color="blue", label="Data") plt.plot(x, model.predict(x), color="red", label="Regression line") plt.legend() plt.xlabel("Experience_Years") plt.ylabel("Monthly_Salary") plt.show()

Want to create your own notes?

Join thousands of users writing securely on ProNotepad.