-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython
More file actions
24 lines (20 loc) · 810 Bytes
/
Copy pathPython
File metadata and controls
24 lines (20 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
# Generate some synthetic data to work with.
num_examples = 1000
num_features = 10
X = np.random.rand(num_examples, num_features)
y = np.random.rand(num_examples)
# Split the data into training and test sets.
train_test_split = 0.8
train_size = int(num_examples * train_test_split)
X_train, X_test = X[:train_size], X[train_size:]
y_train, y_test = y[:train_size], y[train_size:]
# Train a simple linear regression model on the training data.
model = LinearRegression()
model.fit(X_train, y_train)
# Evaluate the model on the test data and print the results.
y_pred = model.predict(X_test)
rmse = mean_squared_error(y_test, y_pred)
print(f"Root Mean Squared Error on test set: {rmse:.2f}")