Training a model in python - python

I am trying to learn how to build a model and train it on training set. I have done this using MultinomialNB before in Python but not I am trying to build a custom model using a set of equations. Can someone please lead me in right direction? Thank you for your help.
So when I train the model with MultinomialNB, I use the following code.
clf=MultinomialNB()
clf.fit(xtrain, ytrain)
What I am trying to do now involves an equation for tag prediction A_i where i is the tag I am predicting for a given posts. I am not sure how to go about training a model using this equation A_i.

Related

How to find which model is selected by TPOT

Hi am using TPOT for machine learning I am getting 99% accuracy but I am not sure to which model did it predict can someone help me with this also does it do SMOTE?
If you stored the TPOTClassifier in the variable my_tpot, then you can access the final trained pipeline by accessing the fitted_pipeline_ attribute:
my_tpot = TPOTClassifier()
my_tpot.fit(…)
print(my_tpot.fitted_pipeline_)

Late Fusion with SVM and Neural Network

I have a question regarding the process to make a late fusion between SVM (Linear) and a NeuralNetwork (NN),
I have done some research and I found that concatenated the clf.predict_prob of SVM and Model.predic of NN, I should train the new model, however, these scores are for the test data and I cannot figure what to do with the training data.
In other words, I train the new model with the concatenated probability scores of the test data from my two models (SVM and NN) and I test this new model with the same concatenated data, and I'm not really sure of this.
Can you please give me an insight into if this is correct?
After a lot of searching and research I found the solution:
The solution is to train and test a new classifier, in my case it was another Neural Network, with the concatenated probability scores obtained from both data sets (training and test), of the two classifiers, the Linear SVM and the Neural Network.
An example of this of three Linear SVM Late fusion was implemented in python, and can be found in the following link:
https://github.com/JMalhotra7/Learning-image-by-parts-using-early-and-late-fusion-of-auto-encoder-features

How do we find validation error of linear regression and elastic-net using Scikit-learn and python?

When do we use test set and validation set while calculating errors?
I have linear regression and elastic-net models working. I am new to Machine learning with Scikit-learn and Python.
I am trying to solve this problem.
Data Set: UCI Machine Learning Forest Fire data
You can use the test set when you build the model by use the method of minimizing the errors.After you build the model, you can calculate the actual error by using the validation set and then use the error to correct the parameter.I hope this can help you.

Python Word2Vec: understand the trained model itself in detail

Let me make my question clearer:
I am using python gensim.models.Word2Vec to train a word embedding model. Based on my understanding, the model training is in essence a machine learning issue---to train a neural network via a prediction task. For example, if I select parameters to train a skip-gram model, then the model is trained by predicting context words from target word. Once the model is well-trained, word vectors are just obtained from the model.
If my understanding is correct, so since in fact it is a machine learning process and the training goal is to perform well in the prediction task, there should be a loss function during training and the model is supposed to make the loss as low as possible. So, how to know the model loss value for a given set of parameters? Or is there any other metrics that we can know to understand the model itself?
Hope I have made my question clear. In a word, I don't want to evaluate the model by its outputs as in the Google test set http://word2vec.googlecode.com/svn/trunk/questions-words.txt, but I want to understand the model itself as a simple machine learning problem during its training process. Would this be possible?

Classifying new occurances - Multinomial Naive Bayes

So I have currently trained a Multinomial Naive Bayes classifier, using [SKiLearn][1]
Now what I can do is classify test data by using predict.
But if I want to run this every night, as a script, I clearly need to always have a classifier already trained up! Now what I'd like to be able to do, is take classifier coefficients, informative words, and use these to classify new data.
Is this possible - to develop my own method for classification? Or should I be simply training the SkiLearn classifier nightly?
EDIT: One thing, it seems I can do, is retain and save my trained classifier.
However with logistic regression, you can take the coefficients and use these on new data. Is there anything similar to this for NB?
Do you mean [sklearn]? Are you using python? If that is the case, it turns out that [sklearn] provides a function for getting the parameters of the model [get_params(deep=True)] as well as a function for setting them [set_params(**params)].
Therefore, a possible procedure could be:
Training stage:
1) Train the model
2) Get the parameters of the model by using get_params()
3) Save the parameters into a binary file (e.g. by using pickle.dump())
Prediction stage:
1) Load the parameters of the model from the binary file (e.g. by using pickle.load())
2) Set the parameters of the model by using set_params()
3) Classify new data by using the predict() function
Hope that helps.

Categories

Resources