Comments (5)
Have you defined or imported the function anywhere in your code?
from hyperas.
def train_predict(clf, X_train, y_train, X_test, y_test):
Defined like this....later in the code
Not imported anywhere else in the code
from hyperas.
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_predict
X_train_cv, X_test_cv, y_train_cv, y_test_cv = train_test_split(X_train, y_train, test_size = 0.3, random_state=100)
neighbors = []
accuracy = []
for n in range(3,10):
knn = KNeighborsClassifier(n_neighbors=n)
print("Number of neighbors is: {}".format(n))
train_predict(knn, X_train_cv, y_train_cv, X_test_cv, y_test_cv)
clf_ = knn.fit(X_train, y_train)
y_pred = clf_.predict(X_test)
neighbors.append(n)
accuracy.append( str(("%.2f" %(accuracy_score(y_test,y_pred)* 100) )))
accuracy.sort()
neighbors.sort()
plt.bar( list(range(3, 10)), accuracy, tick_label=neighbors, width=0.8, color="rgbymc")
plt.title("Optimizing Neighbours for KNN")
plt.xlabel("Neighbours")
plt.ylabel("accuracy")
plt.ylim(0)
plt.show()
ImportError Traceback (most recent call last)
in
1 from sklearn.neighbors import KNeighborsClassifier
----> 2 from sklearn.model_selection import train_predict
3 X_train_cv, X_test_cv, y_train_cv, y_test_cv = train_test_split(X_train, y_train, test_size = 0.3, random_state=100)
4 neighbors = []
5 accuracy = []
ImportError: cannot import name 'train_predict' from 'sklearn.model_selection' (C:\Users\MyPc\Anaconda3\lib\site-packages\sklearn\model_selection_init_.py)
from hyperas.
def train_clf(clf, X_train, y_train):
return clf.fit(X_train, y_train)
def pred_clf(clf, features, target):
y_pred = clf.predict(features)
return f1_score(target.values, y_pred, pos_label = 1)
def train_predict(clf, X_train, y_train, X_test, y_test):
train_clf(clf, X_train, y_train)
print("F1 score for training set is: {:.4f}".format(pred_clf(clf, X_train, y_train)))
print("F1 score for testing set is: {:.4f}\n".format(pred_clf(clf, X_test, y_test)))
from hyperas.
If your methods are so short, consider just putting them inside your main function that you want to optimise.
Additionally, no such function train_predict
exists inside sklearn.model_selection
. Also consider formatting your code so it's easier to read. Place the code between a pair of ```
from hyperas.
Related Issues (20)
- Cross validation inside 'data' function HOT 5
- UnicodeDecodeError: 'gbk' codec can't decode byte 0xa2 in position 885: illegal multibyte sequence
- UnicodeDecodeError: 'gbk' codec can't decode byte 0xa2 in position 885: illegal multibyte sequence
- UnicodeDecodeError: 'gbk' codec can't decode byte 0xa2 in position 885: illegal multibyte sequence HOT 3
- Optmizing CNN - TypeError: module, class, method, function, traceback, frame, or code object was expected, got tuple HOT 2
- Cannot run hyperas on databricks, [Errno 2] No such file or directory: "/databrikcs/driver/notebook_name" HOT 1
- custom def on kernel_initializer
- How can it be guaranteed to run all combinations if only "choice" is used.
- AttributeError: 'numpy.random.mtrand.RandomState' object has no attribute 'integers' HOT 13
- KeyError: job exception: 'val_acc' HOT 2
- Can Hyperas natively return data regarding all models ran during an optimization cycle? HOT 1
- Why hyperas is executing Raw Text as code HOT 1
- AttributeError: numpy.random.mtrand.RandomState object has no attribute 'integers'
- global variable issue HOT 2
- module 'hyperopt.pyll' has no attribute 'base' HOT 1
- getting issue in this code is there anyone can help me out? It will be greatfull... #Building another model/classifier ISOLATION FOREST from sklearn.ensemble import IsolationForest ifc=IsolationForest(max_samples=len(X_train), contamination=outlier_fraction,random_state=1) ifc.fit(X_train) scores_pred = ifc.decision_function(X_train) y_pred = ifc.predict(X_test) # Reshape the prediction values to 0 for valid, 1 for fraud. y_pred[y_pred == 1] = 0 y_pred[y_pred == -1] = 1 n_errors = (y_pred != Y_test).sum()
- getting issue in this code is there anyone can help me out? It will be greatfull... HOT 1
- I am having error of No such file or directory: 'C:\\Users\\fnur42\\AppData\\Local\\Temp\\ipykernel_3156\\3188587457.py'.This error shows in the best_run,best_model line. What is ipykernel file and how I can create it?
- I always have this error after executing the following code : NameError: name 'x_train' is not defined HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hyperas.