如何将数据集中存在的单个数据训练到已经训练好的神经网络?
How to train single data present in a data set to a already trained neural network?
我已经有一个经过训练的神经网络,
clf = neural_network.MLPClassifier(
activation='relu',
hidden_layer_sizes=(40,40,40,40),
learning_rate='adaptive',
learning_rate_init=0.01,
solver='sgd',
alpha=1e-6,
max_iter=20000,
warm_start=True,
)
我已经训练过了,
clf.fit(X,Y)
这个分类器有两个 类 [0,1]
.
现在,当我一次使用数据集中的一个数据进一步训练它时。
clf.fit([features_1],[1])
弹出错误
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
fav_clf.fit(X_, Y)
File "D:\Python3.5\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py", line 973, in fit
hasattr(self, "classes_")))
File "D:\Python3.5\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py", line 331, in _fit
X, y = self._validate_input(X, y, incremental)
File "D:\Python3.5\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py", line 924, in _validate_input
(self.classes_, classes))
ValueError: warm_start can only be used where `y` has the same classes as in the previous call to fit. Previously got [0 1], `y` has [1]
暂时忘掉warm_start
,努力去理解usage of fit()
。
fit(X, y):
Fit the model to data matrix X and target(s) y.
因此,如果您只提供单个 class 的数据,模型将无法学习任何东西。 warm_start
在 MLPClassifier 中用于:
reuse the solution of the previous call to fit as initialization
因此,训练可以更快,以前训练的权重将用作初始权重,但仍需要访问多个 classes 数据才能区分它们。
现在看到你的问题,我想你想将模型用作 incremental classifier:-
Actually, the ability to learn incrementally from a mini-batch of
instances (sometimes called “online learning”). All estimators
implementing the partial_fit API are candidates.
因此,如果您只是想让模型逐步学习较新的数据,则需要执行 partial_fit()
。但请注意,您必须转 warm_start = False
,才能使用 partial_fit()
。
# First call to partial_fit
clf.partial_fit(X, Y, classes=[0, 1])
# All next calls
clf.partial_fit(X, Y) #<== Here you can pass a single sample.
我已经有一个经过训练的神经网络,
clf = neural_network.MLPClassifier(
activation='relu',
hidden_layer_sizes=(40,40,40,40),
learning_rate='adaptive',
learning_rate_init=0.01,
solver='sgd',
alpha=1e-6,
max_iter=20000,
warm_start=True,
)
我已经训练过了,
clf.fit(X,Y)
这个分类器有两个 类 [0,1]
.
现在,当我一次使用数据集中的一个数据进一步训练它时。 clf.fit([features_1],[1]) 弹出错误
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
fav_clf.fit(X_, Y)
File "D:\Python3.5\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py", line 973, in fit
hasattr(self, "classes_")))
File "D:\Python3.5\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py", line 331, in _fit
X, y = self._validate_input(X, y, incremental)
File "D:\Python3.5\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py", line 924, in _validate_input
(self.classes_, classes))
ValueError: warm_start can only be used where `y` has the same classes as in the previous call to fit. Previously got [0 1], `y` has [1]
暂时忘掉warm_start
,努力去理解usage of fit()
。
fit(X, y): Fit the model to data matrix X and target(s) y.
因此,如果您只提供单个 class 的数据,模型将无法学习任何东西。 warm_start
在 MLPClassifier 中用于:
reuse the solution of the previous call to fit as initialization
因此,训练可以更快,以前训练的权重将用作初始权重,但仍需要访问多个 classes 数据才能区分它们。
现在看到你的问题,我想你想将模型用作 incremental classifier:-
Actually, the ability to learn incrementally from a mini-batch of instances (sometimes called “online learning”). All estimators implementing the partial_fit API are candidates.
因此,如果您只是想让模型逐步学习较新的数据,则需要执行 partial_fit()
。但请注意,您必须转 warm_start = False
,才能使用 partial_fit()
。
# First call to partial_fit
clf.partial_fit(X, Y, classes=[0, 1])
# All next calls
clf.partial_fit(X, Y) #<== Here you can pass a single sample.