+1 vote

So, I recently started with Machine Learning and coding in Python. I've been trying to figure out the partition method used in the Amazon fine food review data from kaggle and its code. What i also can't understand, is the purpose of the last 3 lines of code.

```    %matplotlib inline
import sqlite3
import pandas as pd
import numpy as np
import nltk
import string
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.feature_extraction.text import TfidfVectorizer

from sklearn.feature_extraction.text import CountVectorizer
from sklearn.metrics import confusion_matrix
from sklearn import metrics
from sklearn.metrics import roc_curve, auc
from nltk.stem.porter import PorterStemmer

# using the SQLite Table to read data.
con = sqlite3.connect('./amazon-fine-food-reviews/database.sqlite')

#filtering only positive and negative reviews i.e.
# not taking into consideration those reviews with Score=3
SELECT *
FROM Reviews
WHERE Score != 3
""", con)

# Give reviews with Score>3 a positive rating, and reviews with a
score<3 a negative rating.
def partition(x):
if x < 3:
return 'negative'
return 'positive'

#changing reviews with score less than 3 to be positive vice-versa
actualScore = filtered_data['Score']
positiveNegative = actualScore.map(partition)
filtered_data['Score'] = positiveNegative```

Any help would be greatly appreciated. Thanks.

Dec 13, 2018 810 views

## 1 answer to this question.

You can create an array called actualScore using the column Score from filtered_data

actualScore = filtered_data['Score']

Then create an array positiveNegative coding negative for values less than 3 and positive for values greater than 3.

positiveNegative = actualScore.map(partition)

Then you can overwrite the old column score with the new coded values

filtered_data['Score'] = positiveNegative

Hope this helps!

If you wanna know more about Machine Learning, It's recommended to go for Python Machine Learning course today.

Thank you!

• 13,490 points

## Why should anyone learn Python instead of R for machine learning?

Machine learning is the latest technology everyone ...READ MORE

## R vs MATLAB, which is better with respect to machine learning?

Hello, Both are a good programming language you ...READ MORE

## What is the Difference in Size and Count in pandas (python)?

The major difference is "size" includes NaN values, ...READ MORE

## Which package is used to do data import in R and Python and How do you import SAS data?

We can do data import using multiple ...READ MORE

## On a given dataset would time taken to train n - random forest be equal to time taken to train n X (Decision tree)

No, the time to train the random ...READ MORE

## how do i change string to a list?

suppose you have a string with a ...READ MORE

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote