'Getting the shape of the array from a PKL file
I have this machine learning model that I have saved into a PKL file. In "MC_features" you can see that I have assigned the 21 values in the model to be 0 by default. I am trying to see if there is a way to get the shape of the array from the PKL file so I would not need to manually change the "21" and it will automatically register it from the shape or the number of elements in array.
This is how I saved the PKL file.
Dtree = LinearRegression()
Dtree.fit(X_train, y_train)
import joblib
joblib.dump(Dtree,'MC_Model.pkl')
This is my flask code.
from flask import Flask, request, render_template
import numpy as np
import joblib
app = Flask(__name__)
model = joblib.load('MC_Model.pkl')
@app.route('/', methods=["GET", "POST"])
def home():
# default values for `GET`
cluster = None
material = None
MC_features = [np.zeros((21,), dtype=int)]
MC_text = 'Usage Amount: ???'
if request.method == 'POST':
cluster = request.form.get('cluster')
print('cluster:', cluster)
material = request.form.get('material')
print('material:', material)
if cluster:
index = int(cluster)
MC_features[0][index] = 1.0
if material:
index = int(material)
MC_features[0][index] = 1.0
print(MC_features)
MC_prediction = model.predict(MC_features)
#prediction = [np.random.randint(0, 100)]
MC_text = 'Usage Amount: {}'.format(MC_prediction[0])
return render_template('BOM.html',MC_prediction=MC_text, MC_features=MC_features[0], cluster=cluster, material=material)
Solution 1:[1]
i have same issue. i just found it today
model.feature_names_in_
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KnowNothing JohnSnow |
