Practical 2.ipynb - Colaboratory
Practical 2.ipynb - Colaboratory
pandas as pd
import numpy as np
import scipy as sc
import matplotlib.pyplot as plt
import seaborn as sea
import statistics as st
import sklearn
df = pd.read_csv('/content/weatherHistory.csv.zip')
df.head()
2006-04-01
Partly
0 00:00:00.000 rain 9.472222 7.388889 0.89 14.1197 251
Cloudy
+0200
2006-04-01
Partly
1 01:00:00.000 rain 9.355556 7.227778 0.86 14.2646 259
Cloudy
+0200
2006-04-01
Mostly
2 02:00:00.000 rain 9.377778 9.377778 0.89 3.9284 204
Cloudy
+0200
2006-04-01
Partly
3 03:00:00.000 rain 8.288889 5.944444 0.83 14.1036 269
Cloudy
+0200
df.shape
(96453, 12)
df.dtypes
df.describe()
Apparent Wind
Temperature Wind Speed Visibi
Temperature Humidity Bearing
(C) (km/h)
(C) (degrees)
df.isnull().sum()
Formatted Date 0
Summary 0
Precip Type 517
Temperature (C) 0
Apparent Temperature (C) 0
Humidity 0
Wind Speed (km/h) 0
Wind Bearing (degrees) 0
Visibility (km) 0
Loud Cover 0
Pressure (millibars) 0
Daily Summary 0
dtype: int64
Predictive data
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
# Split the dataset into training and test sets
X_train, X_test, y_train, y_test = train_test_split(df.drop('Temperature (C)', axis=1), df['Temperature (C)'], test_size=0.2)
# Train a linear regression model on the training set
model = LinearRegression()
model.fit(X_train, y_train)
# Generate predictions on the test set
predictions = model.predict(X_test)
# Print the predicted values
print(predictions)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-13-904760d17b7a> in <cell line: 10>()
8 # Train a linear regression model on the training set
9 model = LinearRegression()
---> 10 model.fit(X_train, y_train)
11
12 # Generate predictions on the test set
5 frames
/usr/local/lib/python3.9/dist-packages/pandas/core/generic.py in __array__(self,
dtype)
2068
2069 def __array__(self, dtype: npt.DTypeLike | None = None) ->
np.ndarray:
-> 2070 return np.asarray(self._values, dtype=dtype)
2071
2072 def __array_wrap__(