Hi David — how can we help you?

CommonLounge

Categories

Active In

Deep Learning

11 replies. 6 discussions. Member

Web Development

51 replies. 47 discussions. Moderator

Machine Learning

18 replies. 5 discussions. Member

UI/UX Design

24 replies. 42 discussions. Moderator

Artificial Intelligence

10 replies. 18 discussions. Moderator

CommonLounge Meta

42 replies. 33 discussions. Moderator

Startups

16 replies. 16 discussions. Moderator

Technology

12 replies. 25 discussions. Moderator

Product Management

9 replies. 9 discussions. Moderator

Virtual Reality

14 replies. 13 discussions. Moderator

Featured Contributions

Contributed 6%

2.

tutorial

Event Emitter

Event Emitters play a very important role in the Node.js ecosystem.

The EventEmitter is a module that facilitates communication/interaction between objects in Node. EventEmitter is at the core of Node asynchronous event-driven architecture. Many of Node’s built-in modules inherit from EventEmitter including prominent frameworks like Express.js.

The concept is quite simple: emitter objects emit named events that cause previously registered listeners to be called. So, an emitter object basically has two main features:

- Emitting name events.
- Registering and unregistering listener functions.

It’s kind of like a pub/sub or observer design pattern (though not exactly).

- EventEmitter class

Read more…(1101 words)

Category: Web Development

NaN.

discussion

Looking for helpby David Nyoni

I'm new here can you assist me

Read more…(7 words)

Category: Artificial Intelligence

comment in this discussion

Anant JainInterned at Microsoft Research's ML Group · 2w

Hi David — how can we help you?

Read more… (8 words)

4.

discussion

Looking for help

I'm new here can you assist me

Read more…(7 words)

Category: Artificial Intelligence

Contributed 100%

5.

tutorial

Pro Content

Solution to Hands-on Assignment: Movie Recommender System using Matrix Factorization

Category: Machine Learning

Contributed 100%

6.

tutorial

Pro Content

Solution to Hands-on Assignment: Text Generation using Recurrent Neural Networks

Category: Deep Learning

NaN.

tutorial

End-to-End Example: Using Logistic Regression for predicting Diabetesby Wiki

Category: Machine Learning

comment in this discussion

NaN.

tutorial

Naive Bayes algorithm and text classificationby Wiki

Cards

Scroll

**Naive Bayes** is a widely used classification algorithm. It is a supervised learning algorithm based on Bayes’ Theorem. The word **naive** comes from the assumption of independence among features. That is, if our input vector is (x_{1}, x_{2},...,x_{n}), then x_{i}'s are conditionally independent given *y*.

Let's start with Bayes' theorem (for naive bayes, x is the input and y is the output):

P( y | x ) = \frac{P(y)P(x | y)}{P(x)}

When we have more than one feature, we can rewrite Bayes' theorem as:

P( y | x_1,...,x_n) = \frac{P(y)P(x_1,...,x_n | y)}{P(x_1,x_2,...,x_n)}

Since we are making the assumption that x_{i}'s are conditionally independent given *y*, we can rewrite the above as

P(y|x_1,...,x_n) = \frac{P(y) \prod_{i=1}^{n} P(x_i|y)}{P(x_1,x_2,...,x_n)}

but we also know that *P*(*x _{1}, x_{2}, .., x_{n}*) is a constant given the input, i.e.

P(y|x_1,...,x_n) \propto P(y) \prod_{i=1}^{n} P(x_i|y) \quad \quad (1)

Notice that

- the left hand side is the term we are interested in, probability distribution of the output y given input x.
- P(y) can be estimated by counting the number of times each class y appears in our training data (this is called
__Maximum a Posteriori__estimation). - P(x
_{i}|y) can be estimated by counting the number of times each value of x_{i}appears for each class y in our training data.

Training:

**Estimate P(y)**: P(y=t) = number of times class t appears in the dataset / size of dataset**Estimate P(x**: P(x_{i}|y)_{i}=k|y=t) = number of times x_{i}has value k and y has value t / number of data points of class t

Predicting:

**Estimate P(y|x**: Use above estimated values of P(y) and P(x_{1},...,x_{n})_{i}|y) and equation (1). Thereafter, normalize the values.

There are several variants of naive bayes which use different distributions for P(x_{i}|y) such as gaussian distribution (gaussian naive bayes), multinomial distribution (multinomial naive bayes) and bernoulli distribution (bernoulli naive bayes).

# We will use the iris dataset:# The iris flower data set consists of 50 samples from each of three# species of Iris (Iris setosa, Iris virginica and Iris versicolor).# Four features were measured from each sample: the length and the width# of the sepals and petals, in centimeters.from sklearn.datasets import load_irisfrom sklearn.naive_bayes import GaussianNBimport numpy as np# load the datasetdata = load_iris()model = GaussianNB()model.fit(data.data, data.target)# evalauteprint(model.score(data.data, data.target))# output = 0.96# predictmodel.predict([[4.2, 3, 0.9, 2.1]])# 0 = setosa, 1 = versicolor, and 2 = virginica

Naive bayes is one of the simplest yet effective algorithms for

**Text classification:**For example, we have a number of news articles, and we want to learn to classify if the article is about politics, health, technology, sports or lifestyle.**Spam filtering:**We have a number of emails, and we want to learn to classify if the email is spam or not.**Gender classification:**Given features such as height, weight, etc, predict whether the person is male or female.

Read more…(397 words)

Category: Machine Learning

comment in this discussion

NaN.

tutorial

Naive Bayes algorithm and text classificationby Wiki

Cards

Scroll

**Naive Bayes** is a widely used classification algorithm. It is a supervised learning algorithm based on Bayes’ Theorem. The word **naive** comes from the assumption of independence among features. That is, if our input vector is (x_{1}, x_{2},...,x_{n}), then x_{i}'s are conditionally independent given *y*.

Let's start with Bayes' theorem (for naive bayes, x is the input and y is the output):

P( y | x ) = \frac{P(y)P(x | y)}{P(x)}

When we have more than one feature, we can rewrite Bayes' theorem as:

P( y | x_1,...,x_n) = \frac{P(y)P(x_1,...,x_n | y)}{P(x_1,x_2,...,x_n)}

Since we are making the assumption that x_{i}'s are conditionally independent given *y*, we can rewrite the above as

P(y|x_1,...,x_n) = \frac{P(y) \prod_{i=1}^{n} P(x_i|y)}{P(x_1,x_2,...,x_n)}

but we also know that *P*(*x _{1}, x_{2}, .., x_{n}*) is a constant given the input, i.e.

P(y|x_1,...,x_n) \propto P(y) \prod_{i=1}^{n} P(x_i|y) \quad \quad (1)

Notice that

- the left hand side is the term we are interested in, probability distribution of the output y given input x.
- P(y) can be estimated by counting the number of times each class y appears in our training data (this is called
__Maximum a Posteriori__estimation). - P(x
_{i}|y) can be estimated by counting the number of times each value of x_{i}appears for each class y in our training data.

Training:

**Estimate P(y)**: P(y=t) = number of times class t appears in the dataset / size of dataset**Estimate P(x**: P(x_{i}|y)_{i}=k|y=t) = number of times x_{i}has value k and y has value t / number of data points of class t

Predicting:

**Estimate P(y|x**: Use above estimated values of P(y) and P(x_{1},...,x_{n})_{i}|y) and equation (1). Thereafter, normalize the values.

There are several variants of naive bayes which use different distributions for P(x_{i}|y) such as gaussian distribution (gaussian naive bayes), multinomial distribution (multinomial naive bayes) and bernoulli distribution (bernoulli naive bayes).

# We will use the iris dataset:# The iris flower data set consists of 50 samples from each of three# species of Iris (Iris setosa, Iris virginica and Iris versicolor).# Four features were measured from each sample: the length and the width# of the sepals and petals, in centimeters.from sklearn.datasets import load_irisfrom sklearn.naive_bayes import GaussianNBimport numpy as np# load the datasetdata = load_iris()model = GaussianNB()model.fit(data.data, data.target)# evalauteprint(model.score(data.data, data.target))# output = 0.96# predictmodel.predict([[4.2, 3, 0.9, 2.1]])# 0 = setosa, 1 = versicolor, and 2 = virginica

Naive bayes is one of the simplest yet effective algorithms for

**Text classification:**For example, we have a number of news articles, and we want to learn to classify if the article is about politics, health, technology, sports or lifestyle.**Spam filtering:**We have a number of emails, and we want to learn to classify if the email is spam or not.**Gender classification:**Given features such as height, weight, etc, predict whether the person is male or female.

Read more…(397 words)

Category: Machine Learning

comment in this discussion

Anant JainCo-Founder, Commonlounge · 3w

You have to pass a 2D array to the predict function. See the code above again. It's:

model.predict([[4.2, 3, 0.9, 2.1]])

and not

model.predict([4.2, 3, 0.9, 2.1])

Read more… (19 words)

10.

discussion

Pro Content

Code for End-to-End Example: Using Logistic Regression for predicting Diabetes

Category: Machine Learning

11.

discussion

Pro Content

Solution to Hands-on Project: Digit classification with K-Nearest Neighbors and Data Augmentation

Category: Machine Learning

Load More