In [ ]:
Copied!
from tinyml import evaluate, fit_linear, train_test_split
from tinyml.datasets import housing
X, y = housing()
X.shape
from tinyml import evaluate, fit_linear, train_test_split
from tinyml.datasets import housing
X, y = housing()
X.shape
Hold out 20% of the houses to score the model on data it has not seen.
In [ ]:
Copied!
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, seed=0)
len(y_train), len(y_test)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, seed=0)
len(y_train), len(y_test)
Fit ordinary least squares. coef has one entry per feature: size_sqft, bedrooms, age_years.
In [ ]:
Copied!
model = fit_linear(X_train, y_train)
model.coef, model.intercept
model = fit_linear(X_train, y_train)
model.coef, model.intercept
evaluate returns the root mean squared error, in dollars. Lower is better.
In [ ]:
Copied!
evaluate(y_test, model.predict(X_test))
evaluate(y_test, model.predict(X_test))