python - 在 ml 中调用 fit() 后,训练后的数据存储在哪里?

标签 python machine-learning scikit-learn linear-regression

我是机器学习新手,没有太多Python经验。

在下面的代码中,我们调用 fit() 后训练的数据存储在哪里?调用 predict() 后如何知道数据是否经过训练方法。

我知道这可能是一个愚蠢的问题,但我们将非常感谢您提供一些帮助。谢谢

#Fitting Simple linear regression to the training set
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, y_train) 

#Predicting the Test search results
y_pred = regressor.predict(X_test)

最佳答案

fit() 函数只是将线性模型拟合到您的数据。训练数据已分配给变量 X_train(特征)和 y_train(标签),因此调用 fit() 后不会存储任何训练数据>。但是,您可以保存经过训练/拟合的模型,其中包括使用训练数据近似的参数。

现在回到你的第二个问题,在将模型拟合到数据之前不可能进行预测。如果您尝试在调用 fit() 之前调用 predict(),您将得到 NotFittedError :

Exception class to raise if estimator is used before fitting.

This class inherits from both ValueError and AttributeError to help with exception handling and backward compatibility.

Example:

>>> from sklearn.svm import LinearSVC
>>> from sklearn.exceptions import NotFittedError
>>> try:
...     LinearSVC().predict([[1, 2], [2, 3], [3, 4]])
... except NotFittedError as e:
...     print(repr(e))
NotFittedError("This LinearSVC instance is not fitted yet. Call 'fit' with
appropriate arguments before using this estimator."...)

关于python - 在 ml 中调用 fit() 后,训练后的数据存储在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59766182/

相关文章:

python - 如何在 Linux (virtualbox) 上启动并运行下载的包含许多文件的 python Web 应用程序

python - 带有更新标签的 Tkinter 加载屏幕

python - 在python中求解矩形矩阵以获得具有任意参数的解决方案

matlab - 在templateSVM中设置RBF核的gamma值

machine-learning - 在纯 TensorFlow 中使用有状态 Keras 模型

python - 如何使用 scikit-learn 将数据转换为适合多类分类任务的格式?

python - 在 django 应用程序中将 SSL 与 nginx 结合使用

python - Numpy Broadcast 执行欧式距离矢量化

python-3.x - sklearn knn预测错误: float() argument must be a string or a number,不是 'dict'

python - 使用预测模型估算缺失值