Chapter 28
starter
NotebookPython 3 (ipykernel)8 cells
In [1]python · cell 1
python
!pip freeze | grep scikit-learnOutput
scikit-learn==1.5.0
In [2]python · cell 2
python
!python -VOutput
Python 3.10.13
In [ ]python · cell 3
python
import pickle
import pandas as pdIn [ ]python · cell 4
python
with open('model.bin', 'rb') as f_in:
dv, model = pickle.load(f_in)In [ ]python · cell 5
python
categorical = ['PULocationID', 'DOLocationID']
def read_data(filename):
df = pd.read_parquet(filename)
df['duration'] = df.tpep_dropoff_datetime - df.tpep_pickup_datetime
df['duration'] = df.duration.dt.total_seconds() / 60
df = df[(df.duration >= 1) & (df.duration <= 60)].copy()
df[categorical] = df[categorical].fillna(-1).astype('int').astype('str')
return dfIn [ ]python · cell 6
python
df = read_data('https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_????-??.parquet')In [ ]python · cell 7
python
dicts = df[categorical].to_dict(orient='records')
X_val = dv.transform(dicts)
y_pred = model.predict(X_val)In [ ]python · cell 8
python
