0% found this document useful (0 votes)
2 views2 pages

Pipeline Test Pickle

The document contains Python code that uses the pickle library to load a predictive model and make predictions based on user input data. It includes a warning about invalid feature names and demonstrates the conversion of input data into a DataFrame for prediction. The input features suggest a higher likelihood of survival based on the characteristics of the passenger.

Uploaded by

KL AusZ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Pipeline Test Pickle

The document contains Python code that uses the pickle library to load a predictive model and make predictions based on user input data. It includes a warning about invalid feature names and demonstrates the conversion of input data into a DataFrame for prediction. The input features suggest a higher likelihood of survival based on the characteristics of the passenger.

Uploaded by

KL AusZ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

test pickle

November 6, 2024

[1]: import pickle

[2]: import numpy as np

[3]: pipe = pickle.load(open('pipe.pkl','rb'))

[22]: # Assume user input

test_input2 = np.array([1, 'female', 35.0,2,0,80.0,'C'],dtype = object).


↪reshape(1,7)

[23]: pipe.predict(test_input2)

C:\Users\home\AppData\Local\Programs\Python\Python312\Lib\site-
packages\sklearn\base.py:493: UserWarning: X does not have valid feature names,
but SimpleImputer was fitted with feature names
warnings.warn(
C:\Users\home\AppData\Local\Programs\Python\Python312\Lib\site-
packages\sklearn\base.py:493: UserWarning: X does not have valid feature names,
but SimpleImputer was fitted with feature names
warnings.warn(

[23]: array([1], dtype=int64)

[24]: import pandas as pd

# Define the feature names in the same order as the training data
feature_names = ['Pclass', 'Sex', 'Age', 'SibSp', 'Parch', 'Fare', 'Embarked']

# Convert the input array to a DataFrame with these feature names


test_input2_df = pd.DataFrame(test_input2, columns=feature_names)

# Now predict using the pipeline


prediction = pipe.predict(test_input2_df)
print(prediction)

[1]
1. Pclass: 1 (first class, often associated with higher survival)
2. Sex: female (higher survival rates for women)

1
3. Age: 22.0 (young age, more likely to survive)
4. SibSp: 0 (no siblings/spouses onboard, fewer dependencies)
5. Parch: 0 (no parents/children onboard, fewer dependencies)
6. Fare: 80.0 (a relatively high fare, often associated with first class)
7. Embarked: ‘C’ (Cherbourg, known for higher survival rates)

[ ]:

You might also like