Open Aditi99b opened 7 months ago
import seaborn as sns import pandas as pd from sklearn.model_selection import train_test_split from sklearn.linear_model import LinearRegression from sklearn.preprocessing import OneHotEncoder from sklearn.compose import ColumnTransformer from sklearn.pipeline import Pipeline
attention_data = sns.load_dataset('attention')
print("Attention Data Columns:") print(attention_data.columns) print("\nSample of the Attention Data:") print(attention_data[['subject', 'attention', 'solutions', 'score']].head())
X = attention_data[['subject', 'attention', 'solutions']] y = attention_data['score']
preprocessor = ColumnTransformer( transformers=[ ('cat', OneHotEncoder(), ['attention']) ], remainder='passthrough' )
regressor = LinearRegression()
pipeline = Pipeline([ ('preprocessor', preprocessor), ('regressor', regressor) ])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
pipeline.fit(X_train, y_train)
new_observation = pd.DataFrame({ 'subject': [5], # Put any subject ID 'attention': ['focused'], # Divided or Focused 'solutions': [3] #1, 2, or 3 })
score_prediction = pipeline.predict(new_observation)
print('\nPredicted Score:') print(score_prediction[0])
Aditi Bharadwaj Period 3 Lopez
2021 MCQ Hacks 2021 MCQ Reflections