Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

complete pipeline sample

# Import the hashing vectorizer
from sklearn.feature_extraction.text import HashingVectorizer

# Instantiate the winning model pipeline: pl
pl = Pipeline([
        ('union', FeatureUnion(
            transformer_list = [
                ('numeric_features', Pipeline([
                    ('selector', get_numeric_data),
                    ('imputer', Imputer())
                ])),
                ('text_features', Pipeline([
                    ('selector', get_text_data),
                    ('vectorizer', HashingVectorizer(token_pattern=TOKENS_ALPHANUMERIC,
                                                     non_negative=True, norm=None, binary=False,
                                                     ngram_range=(1, 2))),
                    ('dim_red', SelectKBest(chi2, chi_k))
                ]))
             ]
        )),
        ('int', SparseInteractions(degree=2)),
        ('scale', MaxAbsScaler()),
        ('clf', OneVsRestClassifier(LogisticRegression()))
    ])
# Fit to the training data
pl.fit(X_train, y_train)

# Compute and print accuracy
accuracy = pl.score(X_test, y_test)
print("
Accuracy on budget dataset: ", accuracy)
Comment

PREVIOUS NEXT
Code Example
Python :: graph node structure 
Python :: HIDING AND ENCRYPTING PASSWORDS IN PYTHON USING MASKPASS MODULE 
Python :: print command in python 
Python :: change legend facecolor 
Python :: Customizing plot with axes object 
Python :: critical errors python 
Python :: connection to python debugger failed: socket closed 
Python :: auto indent python code 
Python :: add all columns in django 
Python :: what will be the output of the following python code? x = 123 for i in x: print(i) 
Python :: vectorized function 
Python :: create empty dataframe and concat 
Python :: Count occurrence of each term in dataframe except for NaN 
Python :: the requested url was not found on the server. flask 
Python :: TAKING LIST INPUT IN PYTHON QUESTION 
Python :: python chatbot speech recognition 
Python :: the 100th iteration in python next() 
Python :: accessing element from csv file in python 
Python :: how to add a separator in a menubar pyqt5 
Python :: ValueError: expected sparse matrix with integer values, found float values 
Python :: apply with sf 
Python :: print less than specific number in one row python 
Python :: python check mognodb size 
Python :: what is mapping in os 
Python :: python creare una list comprehension 
Python :: pydrive list shared folder 
Python :: pandas drop a list of rows 
Python :: hovering over canvas item tkinter event 
Python :: cambiar barra de etitulo tkinter 
Python :: existing session SeleniumLibrary Instance.open_browser 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =