import pandas as pd
from sklearn.datasets import fetch_openml
from sklearn.linear_model import LinearRegression
boston = fetch_openml(name="boston", version=1, as_frame=False)
X = boston.data
y = boston.target
print(X.shape)
print(y.shape)
model = LinearRegression()
model.fit(X, y)
pred = model.predict(X)
print("Intercept:", model.intercept_)
print("Coefficients:", model.coef_)
print("First Prediction:", pred[0])
import pandas as pd
import statsmodels.api as sm
from sklearn.datasets import fetch_openml
boston = fetch_openml(name="boston", version=1, as_frame=True)
X = boston.data
y = boston.target
X = X.apply(pd.to_numeric)
y = pd.to_numeric(y)
X_const = sm.add_constant(X)
model = sm.OLS(y, X_const)
model = model.fit()
print(model.summary())
print("First Prediction:", model.predict(X_const)[0])
from sklearn.datasets import fetch_openml
import statsmodels.formula.api as smf
boston = fetch_openml(name="boston", version=1, as_frame=True)
df = boston.frame
df["MEDV"] = df["MEDV"].astype(float)
formula = "MEDV ~ CRIM + ZN + INDUS + CHAS + NOX + RM + AGE + DIS + RAD + TAX + PTRATIO + B + LSTAT"
model = smf.ols(formula=formula, data=df)
results = model.fit()
print(results.summary())
