- import pandas as pd
- from sklearn.model_selection import train_test_split
- from sklearn.linear_model import LinearRegression
- from sklearn.metrics import mean_squared_error
- # Load the data
- regression_data = pd.read_excel('your_file.xlsx', sheet_name='Regression Data')
- # Separate features (X) and target variable (y)
- X = regression_data.drop(columns=['charges'])
- y = regression_data['charges']
- # Split the data into train and test sets (80% train, 20% test)
- X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
- # Train the model
- model = LinearRegression()
- model.fit(X_train, y_train)
- # Predict on the test set
- y_pred = model.predict(X_test)
- # Evaluate the model
- mse = mean_squared_error(y_test, y_pred)
- print("Mean Squared Error:", mse)
[text] J
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: