PythonFile[1]
PythonFile[1]
import numpy as np
sd=1
m=0
x=np.linspace(-2, 2, 10000)
y=(1/(sd*np.sqrt(2*np.pi)))*np.exp(-0.5*((x-m)/sd)**2)
plt.plot(x,y)
plt.grid(True)
plt.show()
Output:
p_mean = df['price'].mean()
a_mean = df['area'].mean()
n = len(df)
plt.figure(figsize=(8, 6))
plt.xlabel("Area")
plt.ylabel("Price")
plt.legend()
plt.grid(True)
plt.show()
Output :
Correlation Coefficient: 0.5359973457780801
import numpy as np
df = pd.read_csv("Salary_Data.csv")
print(df.head())
model = LinearRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
print(f"Intercept: {model.intercept_:.2f}")
print(f"Coefficient: {model.coef_[0]:.2f}")
r2 = r2_score(y_test, y_pred)
print(f"Mean Squared Error: {mse:.2f}")
plt.xlabel("Experience (Years)")
plt.ylabel("Salary")
plt.legend()
plt.show()
Output :
Intercept: 25321.58
Coefficient: 9423.82
R² Score: 0.90
import numpy as np
df = pd.read_csv("Housing.csv")
X = df[['area', 'bathrooms','bedrooms','stories']]
Y = df['price']
model = LinearRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
r2 = r2_score(y_test, y_pred)
print(f"Intercept: {model.intercept_:.2f}")
print(f"Coefficients: {model.coef_}")
plt.xlabel("Area")
plt.ylabel("Price")
plt.legend()
plt.show()
Output :
Intercept: -64342.42
R² Score: 0.51
import numpy as np
df = pd.read_csv("Salary_Data.csv")
X = df[['YearsExperience']]
Y = df['Salary']
poly_reg = PolynomialFeatures(degree=4)
X_poly = poly_reg.fit_transform(X)
model = LinearRegression()
model.fit(X_train_poly, y_train)
y_pred = model.predict(X_test_poly)
r2 = r2_score(y_test, y_pred)
plt.xlabel("YearsExperience")
plt.ylabel("Salary")
plt.legend()
plt.grid(True)
plt.show()
Output :
Intercept: 25321.58
Coefficient: 9423.82
R² Score: 0.90