У меня есть набор данных, в котором мы прогнозируем прибыль компании на основе расходов на НИОКР, администрирование, рыночные расходы и состояние (категориальные). Я сделал одну горячую метку, чтобы изменить категориальную цифру на c.
При прогнозировании прибыли и ручном вводе расходов на НИОКР, администрацию, рыночные расходы и состояние я получаю ошибку.
Код:
rdspend=float(input("R&D Spend: "))
admpend=float(input("Administration Spend: "))
marketspend=float(input("MArket Spend: "))
location= input("Enter Location:")
if location in stateLE.classes_:
features=np.array([[rdspend,admpend,marketspend,location]])
features[:,3]=stateLE.transform(features[:,3])
features=ct.transform(features)
profit=model.predict(features)
print ("Profit is {}".format(profit))
else :
print ("Can't Predict for location you entered")
Ошибка:
R&D Spend: 234
Administration Spend: 234
MArket Spend: 234
Enter Location:New York
C:\Users\ezabhkh\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\lib\arraysetops.py:565: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
mask &= (ar1 != a)
C:\Users\ezabhkh\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\lib\arraysetops.py:569: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
mask |= (ar1 == a)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\core\fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
55 try:
---> 56 return getattr(obj, method)(*args, **kwds)
57
TypeError: '<' not supported between instances of 'int' and 'str'
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-28-d7996a90f8ed> in <module>
7 features=np.array([[rdspend,admpend,marketspend,location]])
8 features[:,3]=stateLE.transform(features[:,3])
----> 9 features=ct.transform(features)
10 profit=model.predict(features)
11 print ("Profit is {}".format(profit))
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\compose\_column_transformer.py in transform(self, X)
586
587 self._validate_features(X.shape[1], X_feature_names)
--> 588 Xs = self._fit_transform(X, None, _transform_one, fitted=True)
589 self._validate_output(Xs)
590
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\compose\_column_transformer.py in _fit_transform(self, X, y, func, fitted)
455 message=self._log_message(name, idx, len(transformers)))
456 for idx, (name, trans, column, weight) in enumerate(
--> 457 self._iter(fitted=fitted, replace_strings=True), 1))
458 except ValueError as e:
459 if "Expected 2D array, got 1D array instead" in str(e):
~\AppData\Local\Continuum\anaconda3\lib\site-packages\joblib\parallel.py in __call__(self, iterable)
1002 # remaining jobs.
1003 self._iterating = False
-> 1004 if self.dispatch_one_batch(iterator):
1005 self._iterating = self._original_iterator is not None
1006
~\AppData\Local\Continuum\anaconda3\lib\site-packages\joblib\parallel.py in dispatch_one_batch(self, iterator)
833 return False
834 else:
--> 835 self._dispatch(tasks)
836 return True
837
~\AppData\Local\Continuum\anaconda3\lib\site-packages\joblib\parallel.py in _dispatch(self, batch)
752 with self._lock:
753 job_idx = len(self._jobs)
--> 754 job = self._backend.apply_async(batch, callback=cb)
755 # A job can complete so quickly than its callback is
756 # called before we get here, causing self._jobs to
~\AppData\Local\Continuum\anaconda3\lib\site-packages\joblib\_parallel_backends.py in apply_async(self, func, callback)
207 def apply_async(self, func, callback=None):
208 """Schedule a func to be run"""
--> 209 result = ImmediateResult(func)
210 if callback:
211 callback(result)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\joblib\_parallel_backends.py in __init__(self, batch)
588 # Don't delay the application, to avoid keeping the input
589 # arguments in memory
--> 590 self.results = batch()
591
592 def get(self):
~\AppData\Local\Continuum\anaconda3\lib\site-packages\joblib\parallel.py in __call__(self)
254 with parallel_backend(self._backend, n_jobs=self._n_jobs):
255 return [func(*args, **kwargs)
--> 256 for func, args, kwargs in self.items]
257
258 def __len__(self):
~\AppData\Local\Continuum\anaconda3\lib\site-packages\joblib\parallel.py in <listcomp>(.0)
254 with parallel_backend(self._backend, n_jobs=self._n_jobs):
255 return [func(*args, **kwargs)
--> 256 for func, args, kwargs in self.items]
257
258 def __len__(self):
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\pipeline.py in _transform_one(transformer, X, y, weight, **fit_params)
705
706 def _transform_one(transformer, X, y, weight, **fit_params):
--> 707 res = transformer.transform(X)
708 # if we have a weight for this transformer, multiply output
709 if weight is None:
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\preprocessing\_encoders.py in transform(self, X)
388 check_is_fitted(self)
389 # validation of X happens in _check_X called by _transform
--> 390 X_int, X_mask = self._transform(X, handle_unknown=self.handle_unknown)
391
392 n_samples, n_features = X_int.shape
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\preprocessing\_encoders.py in _transform(self, X, handle_unknown)
140 # already called above.
141 _, encoded = _encode(Xi, self.categories_[i], encode=True,
--> 142 check_unknown=False)
143 X_int[:, i] = encoded
144
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\preprocessing\_label.py in _encode(values, uniques, encode, check_unknown)
116 else:
117 return _encode_numpy(values, uniques, encode,
--> 118 check_unknown=check_unknown)
119
120
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\preprocessing\_label.py in _encode_numpy(values, uniques, encode, check_unknown)
49 raise ValueError("y contains previously unseen labels: %s"
50 % str(diff))
---> 51 encoded = np.searchsorted(uniques, values)
52 return uniques, encoded
53 else:
~\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\core\fromnumeric.py in searchsorted(a, v, side, sorter)
1244
1245 """
-> 1246 return _wrapfunc(a, 'searchsorted', v, side=side, sorter=sorter)
1247
1248
~\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\core\fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
64 # a downstream library like 'pandas'.
65 except (AttributeError, TypeError):
---> 66 return _wrapit(obj, method, *args, **kwds)
67
68
~\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\core\fromnumeric.py in _wrapit(obj, method, *args, **kwds)
44 except AttributeError:
45 wrap = None
---> 46 result = getattr(asarray(obj), method)(*args, **kwds)
47 if wrap:
48 if not isinstance(result, mu.ndarray):
TypeError: '<' not supported between instances of 'int' and 'str'