我正在使用 Gradio 部署机器学习模型,在 Gradio 上部署后,我在输入和输出显示错误后收到错误
此输出的代码是
import gradio as gr
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import StandardScaler, MinMaxScaler
# Sample data (replace this with your actual data)
X_train = np.array([[230.1, 37.8, 69.2],
[44.5, 39.3, 45.1],
[17.2, 45.9, 69.3],
[151.5, 41.3, 58.5],
[180.8, 10.8, 58.4]])
y_train = np.array([22.1, 10.4, 9.3, 18.5, 12.9])
# Initialize and train your Linear Regression model
scaler = MinMaxScaler()
scaler.fit(X_train)
X_train_scale = scaler.transform(X_train)
lm = LinearRegression()
lm.fit(X_train_scale, y_train)
# Define prediction function
def predict_sales(tv, radio, newspaper):
# Scale the input features
input_features = scaler.transform([[tv, radio, newspaper]])
# Predict sales
prediction = lm.predict(input_features)
return prediction[0]
# Create Gradio Interface
tv_input = gr.Number(label="TV")
radio_input = gr.Number(label="Radio")
newspaper_input = gr.Number(label="Newspaper")
output_text = gr.Textbox(label="Predicted Sales")
gr.Interface(fn=predict_sales,
inputs=[tv_input, radio_input, newspaper_input],
outputs=output_text,
title="Sales Prediction",
description="Enter advertising expenses to predict sales",
debug=True,enable_queue=True).launch()
]
输入和输出已弃用。请改用组件。