Untitled
import matplotlib.pyplot as plt import seaborn as sns # Statistical summary of the relevant columns stat_summary = data[['IN Gross', 'Out Tare (ton)', 'Payload Netto (ton)']].describe() # Scatter plot to visualize the relationship plt.figure(figsize=(12, 6)) # Plotting IN Gross vs Payload Netto plt.subplot(1, 2, 1) sns.scatterplot(x=data['IN Gross'], y=data['Payload Netto (ton)']) plt.title('IN Gross vs Payload Netto') plt.xlabel('IN Gross') plt.ylabel('Payload Netto (ton)') # Plotting Out Tare vs Payload Netto plt.subplot(1, 2, 2) sns.scatterplot(x=data['Out Tare (ton)'], y=data['Payload Netto (ton)']) plt.title('Out Tare vs Payload Netto') plt.xlabel('Out Tare (ton)') plt.ylabel('Payload Netto (ton)') plt.tight_layout() plt.show() stat_summary ## ------------------------------------------------------------- from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split from sklearn.metrics import mean_squared_error, r2_score import numpy as np # Preparing the data for regression analysis X = data[['IN Gross', 'Out Tare (ton)']] # Predictor variables y = data['Payload Netto (ton)'] # Target variable # Splitting the data into training and testing sets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # Creating a linear regression model model = LinearRegression() model.fit(X_train, y_train) # Predicting and evaluating the model y_pred = model.predict(X_test) mse = mean_squared_error(y_test, y_pred) r2 = r2_score(y_test, y_pred) # Coefficients of the model coefficients = model.coef_ intercept = model.intercept_ # Model summary model_summary = { 'Mean Squared Error': mse, 'R^2 Score': r2, 'Coefficients': coefficients, 'Intercept': intercept } model_summary
Leave a Comment