for Robot Artificial Inteligence

13. Constructor

|

Copy Constructor

Main.cpp

#include <iostream>
#include "test.h"

using namespace std;
/* COPY CONSTRUCTOR */

int main()
{

    int a = 10;
    int b = a;

    a = 60;

    cout << "a : " << a << endl; //60
    cout << "b : " << b << endl; //10

    Test obj1(50, 100, 60);
    Test obj2 = obj1;

    obj2.x = 200;
    *(obj1.p) = 700;

    cout << "obj1.x " << obj1.x << endl;
    cout << "*(obj1.p) " << *(obj1.p) << endl;
    cout << "obj1.y " << obj1.y << endl << endl;

    cout << "obj2.x " << obj2.x << endl;
    cout << "*(obj2.p)" << *(obj2.p) << endl;
    cout << "obj2.y " << obj2.y << endl;


    return 0;
}


test.h

#ifndef TEST_H_INCLUDED
#define TEST_H_INCLUDED

class Test
{
    public:
        int x; //50
        int y; //100
        int *p; //60
        Test(const Test &); //copy
        Test(int, int, int);
        ~Test();
};

#endif // TEST_H_INCLUDED

test.cpp

#include "test.h"

Test::Test(int x, int y, int value)
{
        this->x = x;
        this->y = y;
        this->p = new int(value); // because of in head file p is the *pointer
}
Test::~Test()
{
        delete p;
}
Test::Test(const Test & obj) //copy
{
    this->p = new int(*(obj.p)); //because of in head file p is the *pointer
    this->x = obj.x;
    this->y = obj.y;
}

(CONSTRUCTOR)[http://tcpschool.com/cpp/cpp_struct_intro]

  • 구조체(structure type)란 사용자가 C++의 기본 타입을 가지고 새롭게 정의할 수 있는 사용자 정의 타입입니다.
  • 배열이 같은 타입의 변수 집합이라고 한다면, 구조체는 다양한 타입의 변수 집합을 하나의 타입으로 나타낸 것입니다. 이때 구조체를 구성하는 변수를 구조체의 멤버(member) 또는 멤버 변수(member variable) 라고 합니다.
  • C++의 구조체는 변수뿐만 아니라 함수까지도 멤버 변수로 가질 수 있습니다
  • 또한, C++의 구조체는 타입일 뿐만 아니라, 객체 지향 프로그래밍의 핵심이 되는 클래스(class)의 기초가 됩니다
  • 코드와 함께 설명하겠습니다.
struct 구조체이름

{

    멤버변수1의타입 멤버변수1의이름;

    멤버변수2의타입 멤버변수2의이름;

    ...

};

Exercise

#include <iostream>

using namespace std;
/* DATA STRUCTURES */

struct personalData
{
    string name;
    string surname;
    string telephoneNumber;
    short age;
}a,b;
void test(personalData *);
int main()
{
    personalData person[5];
    a.age =50;

   // cout << a.age << endl;
    person[0].name = "Arkadiusz";
    person[1].name = "Wiola";
    person[0].surname = "Wlodarczyk";
    person[0].telephoneNumber = "606102340";
    person[0].age = 22;
/*
    cout << person[0].name << endl;
    cout << person[0].surname << endl;
    cout << person[0].telephoneNumber << endl;
    cout << person[0].age << endl;
*/
/*
    cout << (*person).name << endl;
    cout << (*&person[0]).name << endl;
    cout << (person+1)->name << endl;
*/
    personalData *p = person;
    personalData *p = person+1; // it is methods to select second array

    cout << p->name << endl;

    test(p); // test(person);

    cout << p->name << endl;
    return 0;
}
void test(personalData *person)
{
    person->name = "Agnes";
}

(friend class)[https://yeolco.tistory.com/116]

  • firend 클래스는 friend로 선언된 다른 클래스의 private 및 protected 멤버에 접근할 수 있습니다.
  • 특정 상황에서 클래스 내에 접근하지 못하도록 private 제한을 두었는데, 필요의 경우 해당 클래스나 함수에서 접근 가능하도록 사용하는것이 friend 클래스 및 함수입니다.

예제

#include <iostream>
#include <string>
using namespace std;

class Friend1 {
private :
    string name;

    friend class Friend2;
};

class Friend2{
public :
    void set_name(Friend1& f, string s) {
        f.name = s;
    }
    void show_name(Friend1& f) {
        cout << f.name << "\n";
    }
};

int main(void) {
    Friend1 f1;
    Friend2 f2;

    f2.set_name(f1, "열코");
    f2.show_name(f1);

    return 0;
}

Friend Class Exercise

main.cpp

#include <iostream>
#include "position.h"

using namespace std;

void setX(Position &, int);
int main()
{
    Position dog(10, 50);

    dog.getPosition();
    setX(dog, 1500);
    dog.getPosition();

    const Position house(100, 200);

    house.getPosition();
//    house.setPosition(444, 444);
    //house.getPosition();

    return 0;
}
void setX(Position & obj, int value)
{
    //Position &obj = dog;
    obj.x = value;
}

position.h

#ifndef POSITION_H_INCLUDED
#define POSITION_H_INCLUDED

class Position
{
    int x, y;
    public:
        Position(int,int);
        ~Position();
        void getPosition() const;
        void setPosition(Position &, int, int); // class 를 받고 인자를 받는다.
        friend void setX(Position &, int);
};

#endif // POSITION_H_INCLUDED

position.cpp

#include "position.h"
#include <iostream>

using namespace std;

Position::Position(int x, int y)
{
    this->x = x;
    this->y = y;
}
Position::~Position()
{

}

void Position::getPosition() const
{
    cout << "x : " << x << endl;
    cout << "y : " << y << endl;
}

void Position::setPosition(Position & obj, int x, int y)
{
    obj.x = x;  // 클래스 안에 변수들을 불러와 바꾼다.
    obj.y = y;
}


Comment  Read more

12. Class

|

Class

  • Class는 파이썬과 마찬가지로 프로젝트를 함에 있어 알고리즘을 나누는 역할을 한다.
  • 예로 어떤 클래스는 더하기를, 어떤 클래스를 곱하기를 역할을 나눠주고 Main Class에다가 합쳐 Main클래스를 간결하게 해준다.

Exercise 1

Main.cpp

#include <iostream>
#include "people.h"
using namespace std;
/* classes */

void test()
{
    PersonalData *pointer = new PersonalData[5];

    delete []pointer;
}

int main()
{

    PersonalData person(20);
    PersonalData person2(50);

    cout << person.getAge()<< endl;
    cout << person2.getAge() << endl;


   // test();
    return 0;
}


people.h

#ifndef PEOPLE_H_INCLUDED
#define PEOPLE_H_INCLUDED

class PersonalData
{
    private:
        short age; // the first argument taken
        int *p;
    public:
        PersonalData(); // 인수가 없으면 이 클래스로 가고 있으면 아래 클래스로 간다.
        PersonalData(short);
        ~PersonalData();
        /**
            This function is setting age. If age is lower than 0, then age = 10.
        */
        void setAge(int);
        short getAge() {return age;}
};

#endif // PEOPLE_H_INCLUDED

people.cpp

#include "people.h"
#include <iostream>

using namespace std;
void PersonalData::setAge(int age)
{
    if (age < 0)
        this->age = 0;
    else
        this->age = age;
}
PersonalData::PersonalData()
{
    static int i = 0;
    cout << "Constructor has been just invoked " << ++i << endl;
    age = 10;

    p = new int[5];
}
PersonalData::PersonalData(short age)
{
    cout <<"this is diff cons" << endl;
    this->age = age;
}
PersonalData::~PersonalData()
{
    static int j = 0;
    cout << "Destructor has been just invoked " << ++j << endl;

    delete [] p;
}

  • Result

Exercise 2

Main.cpp

#include <iostream>
#include "position.h"

using namespace std;

int main()
{
    Position dog(10, 50);

    dog.getPosition();
    dog.setPosition(50, 100);
    dog.getPosition();

    const Position house(100, 200);

    house.getPosition();
//    house.setPosition(444, 444);
    //house.getPosition();

    return 0;
}

Position.h

#ifndef POSITION_H_INCLUDED
#define POSITION_H_INCLUDED

class Position
{
    int x, y;
    public:
        Position(int,int);
        ~Position();
        void getPosition() const;
        void setPosition(int, int);
};

#endif // POSITION_H_INCLUDED

position.cpp

#include "position.h"
#include <iostream>

using namespace std;

Position::Position(int x, int y)
{
    this->x = x;
    this->y = y;
}
Position::~Position()
{

}

void Position::getPosition() const
{
    cout << "x : " << x << endl;
    cout << "y : " << y << endl;
}

void Position::setPosition(int x, int y)
{
    this->x = x;
    this->y = y;
}

(operator)[http://algamza.blogspot.com/2016/03/c-operator-overloading.html]

  • 사용자 정의 클래스 를 사용할 때 연산자에 특별한 의미를 부여할 수 있다는 점은 C++의 멋진 기능 중 하나입니다.
  • 이 기능을 연산자 오버로딩(operator overloading) 이라고 합니다. C++의 연산자 오버로딩은 클래스에 특별 멤버 함수를 다음과 같은 명명 규칙에 따라서 작성해 구현할 수 있습니다.

    Operator 종류

    • = (할당 연산자, assignment operator)
          • (이진 산술 연산자, binary arithmetic operators)
    • += -= = (복합 할당 연산자, compound assignment operators)
    • == != (비교 연산자, comparison operators)

예제

class MyClass {
  public:
  ...
  MyClass & operator=(const MyClass &rhs);
  ...
}

MyClass a, b;
...
b = a;   // b.operator=(a); 와 동일함
MyClass& MyClass::operator=(const MyClass &rhs) {
    // 자기 할당을 확인합니다.
    if (this == &rhs)      // 동일 객체?
        return *this;        // 맞네요. 그럼 할당을 건너뛰고 *this를 반환합니다.

    ... // 할당 해제, 새 공간을 할당하고 값을 복사합니다...

    return *this;
}

Example 3

main.cpp

#include <iostream>
#include "integer.h"

using namespace std;
/* CONVERT constructor - overloading operators */
int main()
{
    Integer a(50);

    int b = a;
    a = 100;
    cout << a.getNr() << endl; //100
    cout << b << endl; // 50

    cout << a + b << endl; //150

    b += a; // a = a + b;

    cout << b << endl; // 150

    cout << a << endl; // 100

    return 0;
}

interger.h

#ifndef INTEGER_H_INCLUDED
#define INTEGER_H_INCLUDED

class Integer
{
    int nr;
    public:
        Integer() { };
        Integer(int);
        operator int();
        int operator+=(Integer);
        int getNr() { return nr; };
};


#endif // INTEGER_H_INCLUDED

interger.cpp

#include "integer.h"
#include <iostream>

using namespace std;
Integer::Integer(int nr)
{
    this->nr = nr;
}
Integer::operator int()
{
    return this->nr;
}
int Integer::operator+=(Integer o)
{
    this->nr = o.getNr() + this->nr; //this는 오퍼레이터에서 받아지는 인수값이다. 그리고 o 는 그 뒤에 받아지는 값
    return this->nr; // 여로 들면 a+=b라고 했을떄 a값이 this이고 b값이 integer o라고 보면 된다.
}

Comment  Read more

12. predict avocado price

|

PROBLEM STATEMENT

  • Data represents weekly 2018 retail scan data for National retail volume (units) and price.
  • Retail scan data comes directly from retailers’ cash registers based on actual retail sales of Hass avocados.
  • Starting in 2013, the table below reflects an expanded, multi-outlet retail data set. Multi-outlet reporting includes an aggregation of the following channels: grocery, mass, club, drug, dollar and military.
  • The Average Price (of avocados) in the table reflects a per unit (per avocado) cost, even when multiple units (avocados) are sold in bags.
  • The Product Lookup codes (PLU’s) in the table are only for Hass avocados. Other varieties of avocados (e.g. greenskins) are not included in this table.
  • Some relevant columns in the dataset:
    • Date - The date of the observation
    • AveragePrice - the average price of a single avocado
    • type - conventional or organic
    • year - the year
    • Region - the city or region of the observation
    • Total Volume - Total number of avocados sold
    • 4046 - Total number of avocados with PLU 4046 sold
    • 4225 - Total number of avocados with PLU 4225 sold
    • 4770 - Total number of avocados with PLU 4770 sold

Importing Data

  • You must install fbprophet package as follows: pip install fbprophet
  • If you encounter an error, try: conda install -c conda-forge fbprophet
  • Prophet is open source software released by Facebook’s Core Data Science team.
  • Prophet is a procedure for forecasting time series data based on an additive model where non-linear trends are fit with yearly, weekly, and daily seasonality, plus holiday effects.
  • Prophet works best with time series that have strong seasonal effects and several seasons of historical data.
  • For more information, please check this out: https://research.fb.com/prophet-forecasting-at-scale/ https://facebook.github.io/prophet/docs/quick_start.html#python-api
# import libraries
import pandas as pd # Import Pandas for data manipulation using dataframes
import numpy as np # Import Numpy for data statistical analysis
import matplotlib.pyplot as plt # Import matplotlib for data visualisation
import random
import seaborn as sns
from fbprophet import Prophet
# the class for prophet of big data
# made from facebook's team
# dataframes creation for both training and testing datasets
avocado_df = pd.read_csv('avocado.csv')
# Let's view the head of the training dataset
avocado_df.head()

# Let's view the last elements in the training dataset
avocado_df.tail(20)

avocado_df = avocado_df.sort_values("Date")
# we sort data thuugh date (sort_values)
plt.figure(figsize=(10,10))
plt.plot(avocado_df['Date'], avocado_df['AveragePrice'])

# Bar Chart to indicate the number of regions
plt.figure(figsize=[25,12])
sns.countplot(x = 'region', data = avocado_df)
# useualy sns class (x, data)
plt.xticks(rotation = 45)

(array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
        34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
        51, 52, 53]), <a list of 54 Text xticklabel objects>)

# Bar Chart to indicate the year
plt.figure(figsize=[25,12])
sns.countplot(x = 'year', data = avocado_df)
plt.xticks(rotation = 45)
#plit.xticks is that set locations and label
# (array([0, 1, 2, 3]), <a list of 4 Text xticklabel objects>)

avocado_prophet_df = avocado_df[['Date', 'AveragePrice']]
# what we want to prophet though data and averageprice in future.
# so all we need is ‘DATE' and 'AveragePrice'
avocado_prophet_df
          Date 	AveragePrice
11569 	2015-01-04 	1.75
9593 	2015-01-04 	1.49
10009 	2015-01-04 	1.68
1819 	2015-01-04 	1.52
9333 	2015-01-04 	1.64
2807 	2015-01-04 	0.75
1195 	2015-01-04 	0.85
10269 	2015-01-04 	1.50
103 	2015-01-04 	1.00
1143 	2015-01-04 	0.80
623 	2015-01-04 	0.74
10425 	2015-01-04 	1.82
1871 	2015-01-04 	1.01
11673 	2015-01-04 	1.80
10945 	2015-01-04 	1.81
2547 	2015-01-04 	1.15
11725 	2015-01-04 	1.72
10477 	2015-01-04 	1.56
2131 	2015-01-04 	1.05

Make Predictions

avocado_prophet_df = avocado_prophet_df.rename(columns={'Date':'ds', 'AveragePrice':'y'})
# rename the 'key' names
#in order fro prophet to do quickly.
avocado_prophet_df
            ds 	    y
11569 	2015-01-04 	1.75
9593 	2015-01-04 	1.49
10009 	2015-01-04 	1.68
1819 	2015-01-04 	1.52
9333 	2015-01-04 	1.64
2807 	2015-01-04 	0.75
1195 	2015-01-04 	0.85
10269 	2015-01-04 	1.50
103 	2015-01-04 	1.00
1143 	2015-01-04 	0.80
623 	2015-01-04 	0.74
10425 	2015-01-04 	1.82
1871 	2015-01-04 	1.01
11673 	2015-01-04 	1.80
10945 	2015-01-04 	1.81
2547 	2015-01-04 	1.15
11725 	2015-01-04 	1.72
10477 	2015-01-04 	1.56
2131 	2015-01-04 	1.05
259 	2015-01-04 	1.02
415 	2015-01-04 	1.19
2495 	2015-01-04 	1.00
9177 	2015-01-04 	1.79
10113 	2015-01-04 	1.22
2339 	2015-01-04 	1.01
2235 	2015-01-04 	0.99
2703 	2015-01-04 	0.95
1975 	2015-01-04 	1.20
9437 	2015-01-04 	1.73
1611 	2015-01-04 	1.05
... 	... 	...
m = Prophet()
m.fit(avocado_prophet_df)
# pass along our data frame
#how can we train the model.
# we're just trying to train the kind of a model to try to predict the future in a way
# Forcasting into the future
future = m.make_future_dataframe(periods=365)
# make prediction future.
#"365" predict one year
forecast = m.predict(future)
forecast

figure = m.plot(forecast, xlabel='Date', ylabel='Price')

figure3 = m.plot_components(forecast)

PART 2

# dataframes creation for both training and testing datasets
avocado_df = pd.read_csv('avocado.csv')
# select specific region
avocado_df

avocado_df_sample = avocado_df[avocado_df['region']=='West']
# take a specific region
avocado_df_sample

avocado_df_sample = avocado_df_sample.sort_values("Date")
avocado_df_sample

plt.figure(figsize=(10,10))
plt.plot(avocado_df_sample['Date'], avocado_df_sample['AveragePrice'])

avocado_df_sample = avocado_df_sample.rename(columns={'Date':'ds', 'AveragePrice':'y'})
m = Prophet()
m.fit(avocado_df_sample)
# Forcasting into the future
future = m.make_future_dataframe(periods=365)
forecast = m.predict(future)
figure = m.plot(forecast, xlabel='Date', ylabel='Price')

figure3 = m.plot_components(forecast)

Comment  Read more

11. start Project in codeblock

|

Project start

  • Create Project folder
  • and it will be two folder : sources, Headers.
  • and create main.cpp

main.cpp

#include <iostream>
#include "ourfirstlibrary.h"
using namespace std;
/* preprocessor directives and multi-file project */

#define PI 3.14

int main()
{
    showHelp();
    cout << a << endl;
    return 0;
}

```c

- and create outfirstlibrary.h
> outfirstlibrary.h

#ifndef OURFIRSTLIBRARY_H_INCLUDED #define OURFIRSTLIBRARY_H_INCLUDED

extern int a; //external (oustide) it means that here we do not reserve MEMORY for variable a /** this is going to help you **/ void showHelp();

#endif // OURFIRSTLIBRARY_H_INCLUDED


- and create outfirstlibrary.cpp
> outfirstlibrary.cpp


```c
#include <iostream>
#include "ourfirstlibrary.h"
using namespace std;

int a = 50;
void showHelp()
{
    cout << "this is help" << endl;
}
  • Head file은 cpp 파일들을 연결시켜주는 역할을 한다. (python 으로 치면 import를 하기 위해 만들어저있는 파일들)
  • head file이 이용되는 이유는 각 파일마다 분류가 나누어 져있는데 나중에 Main 클래스에다가 Import하기 위함이다.

Comment  Read more

11. Amazon Review

|

DATA OVERVIEW

  • Dataset consists of 3000 Amazon customer reviews, star ratings, date of review, variant and feedback of various amazon Alexa products like Alexa Echo, Echo dots
  • The objective is to discover insights into consumer reviews and perfrom sentiment analysis on the data.
  • Dataset: www.kaggle.com/sid321axn/amazon-alexa-reviews
  • PLEASE MAKE SURE TO INSTALL WORDCLOUD: pip install wordcloud
# import libraries
import pandas as pd # Import Pandas for data manipulation(조정) using dataframes
import numpy as np # Import Numpy for data statistical analysis
import matplotlib.pyplot as plt # Import matplotlib for data visualisation(시각화)
import seaborn as sns # Statistical data visualization library.
%matplotlib inline
# matplotlib inline is that for jupiter note to prompht seeing plot
df_alexa = pd.read_csv('amazon_alexa.tsv', sep='\t') #"\t" seperator information of file

#、<- \t tab, \n new line, \s - blank space
# to read '.tsv' or csv function is 'pd.read_csv'
df_alexa.head()

df_alexa.keys()
# to read column '0'
# Index(['rating', 'date', 'variation', 'verified_reviews', 'feedback'], dtype='object')
df_alexa.tail()

df_alexa['verified_reviews']
0                                           Love my Echo!
1                                               Loved it!
2       Sometimes while playing a game, you can answer...
3       I have had a lot of fun with this thing. My 4 ...
4                                                   Music
5       I received the echo as a gift. I needed anothe...
6       Without having a cellphone, I cannot use many ...
7       I think this is the 5th one I've purchased. I'...
8                                             looks great
9       Love it! I’ve listened to songs I haven’t hear...
10      I sent it to my 85 year old Dad, and he talks ...
11      I love it! Learning knew things with it eveyda...
12      I purchased this for my mother who is having k...
13                                     Love, Love, Love!!
14                               Just what I expected....
15                              I love it, wife hates it.
16      Really happy with this purchase.  Great speake...
17      We have only been using Alexa for a couple of ...
18      We love the size of the 2nd generation echo. S...
19      I liked the original Echo. This is the same bu...
20      Love the Echo and how good the music sounds pl...
21      We love Alexa! We use her to play music, play ...
22      Have only had it set up for a few days. Still ...
23      I love it. It plays my sleep sounds immediatel...
24      I got a second unit for the bedroom, I was exp...
25                                        Amazing product
26      I love my Echo. It's easy to operate, loads of...
27                              Sounds great!! Love them!
28      Fun item to play with and get used to using.  ...
29                                Just like the other one
                              ...                        
3120                                                     
3121    I like the hands free operation vs the Tap. We...
3122    I dislike that it confuses my requests all the...
3123                                                     
3124    Love my Alexa! Actually have 3 throughout the ...
3125    This product is easy to use and very entertain...
3126                                                     
3127    works great but speaker is not the good for mu...
3128      Outstanding product - easy to use.  works great
3129    We have six of these throughout our home and t...
3130            Use the product for music and it’s great!
3131                           Easy to set-up and to use.
3132                                     It works great!!
3133    I like having more Alexa devices in my house a...
3134                                           PHENOMENAL
3135                 I loved it does exactly what it says
3136    I used it to control my smart home devices. Wo...
3137                                      Very convenient
3138    Este producto llegó y a la semana se quedó sin...
3139              Easy to set up Ready to use in minutes.
3140                                                Barry
3141                                                     
3142    My three year old loves it.  Good for doing ba...
3143           Awesome device wish I bought one ages ago.
3144                                              love it
3145    Perfect for kids, adults and everyone in betwe...
3146    Listening to music, searching locations, check...
3147    I do love these things, i have them running my...
3148    Only complaint I have is that the sound qualit...
3149                                                 Good
Name: verified_reviews, Length: 3150, dtype: object
df_alexa.info() #  non-null means there is no missing information.
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3150 entries, 0 to 3149
Data columns (total 5 columns):
rating              3150 non-null int64
date                3150 non-null object
variation           3150 non-null object
verified_reviews    3150 non-null object
feedback            3150 non-null int64
dtypes: int64(2), object(3)
memory usage: 123.1+ KB

df_alexa.describe() # count is how many people rating.
# 4.46 is good thing like the rate peoplse rated by means like it is high
# feed bace is 0~1
# standard devation.(표준편차)

       	rating 	feedback
count 3150.000  3150.000
mean 	4.463175 	0.918413
std 	1.068506 	0.273778
min 	1.000000 	0.000000
25% 	4.000000 	1.000000
50% 	5.000000 	1.000000
75% 	5.000000 	1.000000
max 	5.000000 	1.000000

VISUALIZING THE DATA

positive = df_alexa[df_alexa['feedback']==1] # 1 is possitive feedback
# only take a raw which is value is one in feedback colum
negative = df_alexa[df_alexa['feedback']==0] # 0 is negative feedback
# only take a raw which is value is zero in feedback colum
negative
rating 	date 	variation 	verified_reviews 	 feedback
46 	2 	30-Jul-18 	Charcoal Fabric 	It's like Siri, in fact, Siri answers more acc... 	0
111 	2 	30-Jul-18 	Charcoal Fabric 	Sound is terrible if u want good music too get... 	0
141 	1 	30-Jul-18 	Charcoal Fabric 	Not much features. 	0
162 	1 	30-Jul-18 	Sandstone Fabric 	Stopped working after 2 weeks ,didn't follow c... 	0
176 	2 	30-Jul-18 	Heather Gray Fabric 	Sad joke. Worthless. 	0
187 	2 	29-Jul-18 	Charcoal Fabric 	Really disappointed Alexa has to be plug-in to... 	0
205 	2 	29-Jul-18 	Sandstone Fabric 	It's got great sound and bass but it doesn't w... 	0
233 	2 	29-Jul-18 	Sandstone Fabric 	I am not super impressed with Alexa. When my P... 	0
299 	2 	29-Jul-18 	Charcoal Fabric 	Too difficult to set up. It keeps timing out ... 	0
341 	1 	28-Jul-18 	Charcoal Fabric 	Alexa hardly came on.. 	0
350 	1 	31-Jul-18 	Black 	Item no longer works after just 5 months of us... 	0
361 	1 	29-Jul-18 	Black 	This thing barely works. You have to select 3r... 	0
368 	1 	28-Jul-18 	Black 	I returned 2 Echo Dots & am only getting refun... 	0
369 	1 	28-Jul-18 	Black 	not working 	0
373 	1 	27-Jul-18 	Black 	I'm an Echo fan but this one did not work 	0
374 	1 	26-Jul-18 	Black 		0
376 	2 	26-Jul-18 	Black 	Doesn't always respond when spoken to with pro... 	0
381 	1 	25-Jul-18 	White 	It worked for a month or so then it stopped. I... 	0
382 	2 	25-Jul-18 	Black 	Poor quality. Gave it away. 	0
388 	1 	24-Jul-18 	Black 	Never could get it to work. A techie friend lo... 	0
394 	2 	22-Jul-18 	White 	Initially, this echo dot worked very well. Ove... 	0
396 	1 	20-Jul-18 	Black 	I bought an echo dot that had been refurbished... 	0
398 	1 	19-Jul-18 	Black 	Dont trust this.... 	0
406 	1 	16-Jul-18 	White 		0
418 	1 	13-Jul-18 	Black 	I wanted to use these as a radio and intercom ... 	0
420 	1 	12-Jul-18 	Black 	Item has never worked. Out of box it is broken... 	0
424 	1 	11-Jul-18 	Black 	Great product but returning for new Alexa Dot.... 	0
434 	1 	9-Jul-18 	Black 	&#34;NEVER BUY CERTIFIED AND REFURBISHED ECHO ... 	0
470 	1 	1-Jul-18 	White 	This item did not work. Certified refurbished ... 	0
473 	2 	29-Jun-18 	White 	None 	0
... 	... 	... 	... 	... 	...
2688 	2 	30-Jul-18 	Black Dot 	Weak sound. Compared to the Google Home Mini t... 	0
2696 	1 	30-Jul-18 	Black Dot 	Echo Dot responds to us when we aren't even ta... 	0
2697 	1 	30-Jul-18 	White Dot 	NOT CONNECTED TO MY PHONE PLAYLIST :( 	0
2716 	2 	30-Jul-18 	Black Dot 	The only negative we have on this product is t... 	0
2740 	1 	30-Jul-18 	Black Dot 	I didn’t order it 	0
2745 	1 	30-Jul-18 	White Dot 	The product sounded the same as the emoji spea... 	0
2812 	1 	30-Jul-18 	Black Dot 	I am quite disappointed by this product.There ... 	0
2823 	2 	30-Jul-18 	Black Dot 	Nope. Still a lot to be improved. For most of ... 	0
2842 	1 	30-Jul-18 	Black Dot 	I reached out to Amazon, because the device wa... 	0
2851 	1 	30-Jul-18 	Black Dot 	I didn't like that almost everytime i asked Al... 	0
2866 	1 	30-Jul-18 	Black Dot 	The volume is very low 	0
2876 	1 	30-Jul-18 	Black Dot 		0
2892 	1 	30-Jul-18 	Black Dot 	Cheap and cheap sound. 	0
2909 	2 	30-Jul-18 	Black Dot 	For the price, the product is nice quality and... 	0
2922 	1 	30-Jul-18 	White Dot 	Used twice not working!!!!!!! 	0
2932 	1 	30-Jul-18 	Black Dot 	This device does not interact with my home fil... 	0
2940 	2 	30-Jul-18 	White Dot 	Not all that happy. The speaker isn’t great an... 	0
2945 	2 	30-Jul-18 	Black Dot 	When you think about it this really doesn’t do... 	0
2962 	1 	30-Jul-18 	Black Dot 	This worked well for about 6 months but then s... 	0
2964 	2 	30-Jul-18 	Black Dot 	Ask it to play Motown radio on Pandora and it ... 	0
2979 	1 	30-Jul-18 	White Dot 		0
3010 	2 	30-Jul-18 	Black Dot 	Sound is terrible. Cannot pair with echo to pl... 	0
3016 	1 	30-Jul-18 	White Dot 	I am having real difficulty working with the E... 	0
3024 	1 	30-Jul-18 	Black Dot 	I was really happy with my original echo so i ... 	0
3039 	2 	30-Jul-18 	Black Dot 	Weak sound. Compared to the Google Home Mini t... 	0
3047 	1 	30-Jul-18 	Black Dot 	Echo Dot responds to us when we aren't even ta... 	0
3048 	1 	30-Jul-18 	White Dot 	NOT CONNECTED TO MY PHONE PLAYLIST :( 	0
3067 	2 	30-Jul-18 	Black Dot 	The only negative we have on this product is t... 	0
3091 	1 	30-Jul-18 	Black Dot 	I didn’t order it 	0
3096 	1 	30-Jul-18 	White Dot 	The product sounded the same as the emoji spea... 	0
sns.countplot(df_alexa['feedback'], label = "Count")
# how many possitive and negative
# label is the what we pointg on.

sns.countplot(x = 'rating', data = df_alexa)
#countplot is that just count for

df_alexa['rating'].hist(bins = 5)
#bin is how many bar we will display on the plot

plt.figure(figsize = (40,15))
sns.barplot(x = 'variation', y='rating', data=df_alexa, palette = 'deep')
# this is showing all of the data they got
#variation : 변화

WORD CLOUD

  • we can know how many the word repeated and we can know what is the word used by
    words = df_alexa['verified_reviews'].tolist()# this is the column just we interested in
    # like 생략 인덱스 와 라벨
    #we elminate the blank
    #tolist <- it is transform all the word into the list of the word
    #because we dont need to have blank
    #with `,`
    # like we dont maek a list make it one into list
    len(words)
    # 3150
    print(words)
    
['Love my Echo!', 'Loved it!', 'Sometimes while playing a game, you can answer a question correctly but Alexa says you got it wrong and answers the same as you.  I like being able to turn lights on and off while away from home.', 'I have had a lot of fun with this thing. My 4 yr old learns about dinosaurs, i control the lights and play games like categories. Has nice sound when playing music as well.', 'Music', 'I received the echo as a gift. I needed another Bluetooth or something to play music easily accessible, and found this smart speaker. Can’t wait to see what else it can do.', 'Without having a cellphone, I cannot use many of her features. I have an iPad but do not see that of any use.  It IS a great alarm.  If u r almost deaf, you can hear her alarm in the bedroom from out in the living room, so that is reason enough to keep her.It is fun to ask random questions to hear her response.  She does not seem to be very smartbon politics yet.', "I think this is the 5th one I've purchased. I'm working on getting one in every room of my house. I really like what features they offer specifily playing music on all Echos and controlling the lights throughout my house.", 'looks great', 'Love it! I’ve listened to songs I haven’t heard since childhood! I get the news, weather, information! It’s great!', 'I sent it to my 85 year old Dad, and he talks to it constantly.', "I love it! Learning knew things with it eveyday! Still figuring out how everything works but so far it's been easy to use and understand. She does make me laugh at times", 'I purchased this for my mother who is having knee problems now, to give her something to do while trying to over come not getting around so fast like she did.She enjoys all the little and big things it can do...Alexa play this song, What time is it and where, and how to cook this and that!', 'Love, Love, Love!!', 'Just what I expected....', 'I love it, wife hates it.', 'Really happy with this purchase.  Great speaker and easy to set up.', 'We have only been using Alexa for a couple of days and are having a lot of fun with our new toy. It like having a new household member! We are trying to learn all the different featues and benefits that come with it.', 'We love the size of the 2nd generation echo. Still needs a little improvement on sound', "I liked the original Echo. This is the same but shorter and with greate']

WaterMark to PDF

words_as_one_string =" ".join(words) # this " " <- it is technical function to put all the word into together
# join the `word` into ` ` inside. like just fill word out in ` ` blank space
# we need to make one single string out of it.
# so we need to merge word all into together
# it remove []<- list branket
words_as_one_string
'Love my Echo! Loved it! Sometimes while playing a game, you can answer a question correctly but Alexa says you got it wrong and answers the same as you.  I like being able to turn lights on and off while away from home. I have had a lot of fun with this thing. My 4 yr old learns about dinosaurs, i control the lights and play games like categories. Has nice sound when playing music as well. Music I received the echo as a gift. I needed another Bluetooth or something to play music easily accessible, and found this smart speaker. Can’t wait to see what else it can do. Without having a cellphone, I cannot use many of her features. I have an iPad but do not see that of any use.  It IS a great alarm.  If u r almost deaf, you can hear her alarm in the bedroom from out in the living room, so that is reason enough to keep her.It is fun to ask random questions to hear her response.  She does not seem to be very smartbon politics yet. I think this is the 5th one I\'ve purchased. I\'m working on getting one in every room of my house. I really like what features they offer specifily playing music on all Echos and controlling the lights throughout my house. looks great Love it! I’ve listened to songs I haven’t heard since childhood! I get the news, weather, information! It’s great! I sent it to my 85 year old Dad, and he talks to it constantly. I love it! Learning knew things with it eveyday! Still figuring out how everything works but so far it\'s been easy to use and understand. She does make me laugh at times I purchased this for my mother who is having knee problems now, to give her something to do while trying to over come not getting around so fast like she did.She enjoys all the little and big things it can do...Alexa play this song, What time is it and where, and how to cook this and that! Love, Love, Love!! Just what I expected.... I love it, wife hates it. Really happy with this purchase.  Great speaker and easy to set up. We have only been using Alexa for a couple of days and are having a lot of fun with our new toy. It like having a new household member! We are trying to learn all the different featues and benefits that come with it. We love the size of the 2nd generation echo. Still needs a little improvement on sound I liked the original Echo. This is the same but shorter and with greater fabric/color choices. I miss the volume ring on top, now it\'s just the plus/minus buttons. Not a big deal but the ring w as comforting. :) Other than that, well I do like the use of a standard USB charger /port instead of the previous round pin. Other than that, I guess it sounds the same, seems to work the same, still answers to Alexa/Echo/Computer. So what\'s not to like? :) Love the Echo and how good the music sounds playing off it. Alexa understands most commands but it is difficult at times for her to find specific playlists or songs on Spotify. She is good with Amazon Music but is lacking in other major programs. We love Alexa! We use her to play music, play radio through iTunes, play podcasts through Anypod, and set reminders. We listen to our flash briefing of news and weather every morning. We rely on our custom lists. We like being able to voice control the volume. We\'re sure we\'ll continue to find new uses.Sometimes it\'s a bit frustrating when Alexa doesn\'t understand what we\'re saying. Have only had it set up for a few days. Still adding smart home devices to it. The speaker is great for playing music. I like the size, we have it stationed on the kitchen counter and it’s not intrusive to look at. I love it. It plays my sleep sounds immediately when I ask I got a second unit for the bedroom, I was expecting the sounds to be improved but I didnt really see a difference at all.  Overall, not a big improvement over the 1st generation. Amazing product I love my Echo. It\'s easy to operate, loads of fun.It is everything as advertised. I use it mainly to play my favorite tunes and test Alexa\'s knowledge. Sounds great!! Love them! Fun item to play with and get used to using.  Sometimes has hard time answering the questions you ask, but I think it will be better. Just like the other one Still learning all the capabilities...but so far pretty pretty pretty good I like it She works well. Needs a learning command  for unique, owners and users like. Alexa “learn” Tasha’s birthday.  Or Alexa “learn” my definition of Fine. Etc. other than that she is great The speakers sound pretty good for being so small and setup is pretty easy.  I bought two and the reason I only rate it a 3 is I have followed the instructions
len(words_as_one_string)
# 419105
from wordcloud import WordCloud

plt.figure(figsize=(20,20))
plt.imshow(WordCloud().generate(words_as_one_string))
# this is the function to show the most used word in the string

DATA CLEANING/FEATURE ENGINEERING

from sklearn.feature_extraction.text import CountVectorizer
# sklearn.feature _extraction.txt import Countvectorizer <- how many time 'love' mension in the review
# we need to know from the big data. so we call countvetotizer function.
vectorizer = CountVectorizer()
alexa_countvectorizer = vectorizer.fit_transform(df_alexa['verified_reviews'])
#vectorizer.fit_transform<- translate my verified the reviews into the count vectorizor of word
#transform our review into count of vectorizer
alexa_countvectorizer.shape
# almost 4000 column means that how many word we have
# (3150, 4044)
print(alexa_countvectorizer.toarray()) # convert it to array
[[0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]
 ...
 [0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]]

type(alexa_countvectorizer)
#scipy.sparse.csr.csr_matrix
print(vectorizer.get_feature_names())
#this is simply every single word that have been repeated somehow within the reviews
#can see every signle word
['00', '000', '07', '10', '100', '100x', '11', '1100sf', '12', '129', '12am', '15', '150', '18', '19', '1964', '1990', '1gb', '1rst', '1st', '20', '200', '2000', '2017', '229', '23', '24', '25', '29', '2nd', '2package', '30', '300', '30pm', '34', '360', '39', '3rd', '3x', '3xs', '40', '45', '48', '4am', '4ghz', '4k', '4th', '50', '54', '5am', '5ghz', '5th', '600', '62', '672', '6th', '70', '75', '79', '80', '80s', '81', '83', '85', '88', '888', '8gb', '90', '91', '911', '99', '_specifically_', 'a1', 'a19', 'abay', 'abc', 'abd', 'abilities', 'ability', 'able', 'abode', 'about', 'above', 'absolutely', 'absolutly', 'ac', 'accent', 'acceptable', 'accepting', 'access', 'accessable', 'accessible', 'accessing', 'accessories', 'accesss', 'accident', 'accidentally', 'accompanying', 'accomplish', 'accomplished', 'according', 'accordingly', 'account', 'accounts', 'accuracy', 'accurate', 'accurately', 'accustom', 'acknowledge', 'acoustical', 'across', 'act', 'acting', 'action', 'actions', 'activate', 'activated', 'activates', 'activating', 'activation', 'actively', 'activities', 'acts', 'actually', 'ad', 'adapted', 'adapter', 'adapting', 'add', 'added', 'addict', 'addicted', 'addicts', 'adding', 'addition', 'additional', 'additionally', 'addons', 'addressed', 'addresses', 'adds', 'adept', 'adequate', 'adjacent', 'adjust', 'adjusting', 'adjustment', 'adjusts', 'admit', 'adopters', 'adorable', 'ads', 'adults', 'advance', 'advanced', 'advantage', 'advantages', 'advertise', 'advertised', 'advertisement', 'advertising', 'advice', 'advise', 'advised', 'aesthetic', 'af', 'affirm', 'affirmations', 'afford', 'affordable', 'afraid', 'after', 'afternoon', 'afterwards', 'again', 'age', 'agent', 'ages', 'ago', 'agree', 'agreement', 'ahead', 'ai', 'aide', 'aint', 'air', 'aka', 'al', 'alabama', 'alarm', 'alarms', 'albeit', 'alcohol', 'alert', 'alerts', 'alex', 'alexa', 'alexas', 'alexi', 'alexia', 'alexis', 'alexus', 'algo', 'alive', 'all', 'alleviate', 'allow', 'allowed', 'allowing', 'allows', 'allrecipes', 'almost', 'alone', 'along', 'alongside', 'alot', 'alots', 'aloud', 'alread', 'already', 'alright', 'also', 'altering', 'alternative', 'alternatives', 'although', 'always', 'am', 'amaonmazing', 'amaxing', 'amaze', 'amazed', 'amazin', 'amazing', 'amazingly', 'amazon', 'amazonia', 'amazons', 'ambient', 'american', 'americans', 'among', 'amount', 'amounts', 'amozon', 'amplifier', 'amused', 'amusing', 'an', 'analog', 'and', 'android', 'ands', 'angle', 'annoying', 'another', 'answer', 'answered', 'answering', 'answers', 'ant', 'anti', 'anticipate', 'anticipated', 'any', 'anybody', 'anyhow', 'anylist', 'anymore', 'anyone', 'anypod', 'anything', 'anytime', 'anyway', 'anyways', 'anywhere', 'apartment', 'app', 'apparent', 'apparently', 'appealing', 'appear', 'appears', 'apple', 'appliance', 'appliances', 'application', 'applications', 'appointments', 'appreciated', 'apprehensive', 'approaching', 'appropriate', 'approximately', 'apps', 'are', 'area', 'areas', 'aren', 'arent', 'argue', 'argument', 'arguments', 'arises', 'arlo', 'arm', 'around', 'array', 'arrive', 'arrived', 'arriving', 'articles', 'artist', 'artists', 'as', 'asap', 'ase', 'ask', 'asked', 'askes', 'asking', 'asleep', 'aspect', 'aspects', 'ass', 'assigned', 'assist', 'assistance', 'assistant', 'assume', 'assumed', 'assuming', 'assumption', 'at', 'atención', 'atmosphere', 'atrás', 'attach', 'attached', 'attachment', 'attempt', 'attempted', 'attempting', 'attention', 'attractive', 'audible', 'audibles', 'audio', 'audioapple', 'audiobook', 'audiobooks', 'audiophile', 'august', 'aunt', 'auto', 'automatic', 'automatically', 'automation', 'aux', 'auxiliary', 'av', 'avail', 'availability', 'available', 'avoid', 'awake', 'aware', 'away', 'awesome', 'awful', 'awhile', 'awkward', 'awsome', 'b073sqyxtw', 'baby', 'back', 'background', 'backgrounds', 'backyard', 'bad', 'baffle', 'baffled', 'ball', 'ban', 'band', 'bandwagon', 'bandwidth', 'bang', 'bar', 'bare', 'barely', 'bargain', 'bark', 'barn', 'barret', 'barry', 'base', 'baseball', 'based', 'basement', 'basic', 'basically', 'bass', 'bathroom', 'bathrooms', 'batman', 'batteries', 'battery', 'bc', 'be', 'beam', 'beat', 'beautiful', 'beautifully', 'beauty', 'became', 'because', 'becausse', 'become', 'becomes', 'becoming', 'bed', 'bedroom', 'bedrooms', 'bedside', 'bedtime', 'beefy', 'been', 'before', 'begin', 'beginners', 'beginning', 'begun', 'behaved', 'behind', 'being', 'believe', 'believer', 'bells', 'belong', 'below', 'benefit', 'benefits', 'beside', 'besides', 'best', 'bet', 'beta', 'better', 'bettter', 'between', 'beyond', 'bezel', 'bezos', 'bf', 'bff', 'bible', 'big', 'bigger', 'biggest', 'bill', 'billboard', 'bills', 'bing', 'birth', 'birthday', 'bit', 'bizarre', 'black', 'blanket', 'blast', 'blasting', 'blessing', 'blind', 'blink', 'blinks', 'blocking', 'bloods', 'bloomberg', 'blown', 'blows', 'blue', 'blueprints', 'bluetooth', 'blurring', 'board', 'boat', 'bob', 'body', 'bolt', 'bonkers', 'bonus', 'book', 'books', 'boom', 'boombox', 'bo'....
word_count_array = alexa_countvectorizer.toarray()
word_count_array.shape
#(3150, 4044)
word_count_array[0,:] # we grab first raw all the column
# array([0, 0, 0, ..., 0, 0, 0], dtype=int64)
index = 13
plt.plot(word_count_array[0, :])# the showing that how many word mostly repeated the specified row
df_alexa['verified_reviews'][0]
# we can see mostly using word in the review '0' column
# 'Love my Echo!'

df_alexa['length'] = df_alexa['verified_reviews'].apply(len)
#create a new kind of feature which our data frame that has a length into it
#and apply len simply, means that count how many words in 'verified_reviews'
# and added in a new data fram new elemant in the frames
df_alexa.head()

df_alexa['length'].hist(bins=100)

min_char = df_alexa['length'].min()
df_alexa[df_alexa['length'] == min_char]['verified_reviews'].iloc[0]
# this is one of minimum review
#extract 'verified_reviews'
#previously iloc'0' . iloc is primart integer position based (옆으로 글씨가 나오게 하는거)
'😍'
max_char = df_alexa['length'].max()
df_alexa[df_alexa['length'] == max_char]['verified_reviews'].iloc[0]
"Incredible piece of technology.I have this right center of my living room on an island kitchen counter. The mic and speaker goes in every direction and the quality of the sound is quite good. I connected the Echo via Bluetooth to my Sony soundbar on my TV but find the Echo placement and 360 sound more appealing. It's no audiophile equipment but there is good range and decent bass. The sound is more than adequate for any indoor entertaining and loud enough to bother neighbors in my building. The knob on the top works great for adjusting volume. This is my first Echo device and I would imagine having to press volume buttons (on the Echo 2) a large inconvenience and not as precise. For that alone I would recommend this over the regular Echo (2nd generation).The piece looks quality and is quite sturdy with some weight on it. The rubber material on the bottom has a good grip on the granite counter-- my cat can even rub her scent on it without tipping it over.This order came with a free Philips Hue Bulb which I installed along with an extra one I bought. I put the 2 bulbs into my living room floor lamp, turned on the light, and all I had to do was say &#34;Alexa, connect my devices&#34;. The default names for each bulb was assigned as &#34;First light&#34; and &#34;Second light&#34;, so I can have a dimmer floor lamp if I just turned on/off one of the lights by saying &#34;Alexa, turn off the second light&#34;. In the Alexa app, I created a 'Group' with &#34;First light&#34; and &#34;Second light&#34; and named the group &#34;The light&#34;, so to turn on the lamp with both bulbs shining I just say &#34;Alexa, turn on The light&#34;.I was surprised how easily the bulbs connected to the Echo Plus with its built in hub. I thought I would have to buy a hub bridge to connect to my floor lamp power plug. Apparently there is some technology built directly inside the bulb! I was surprised by that. Awesome.You will feel like Tony Stark on this device. I added quite a few &#34;Skills&#34; like 'Thunderstorm sounds' and 'Quote of the day' . Alexa always loads them up quickly. Adding songs that you hear to specific playlists on Amazon Music is also a great feature.I can go on and on and this is only my second day of ownership.I was lucky to buy this for $100 on Prime Day, but I think for $150 is it pretty expensive considering the Echo 2 is only $100. In my opinion, you will be paying a premium for the Echo Plus and you have to decide if the value is there for you:1) Taller and 360 sound unit.2) Volume knob on top that you spin (I think this is a huge benefit over buttons)3) Built in hub for Hue bulbs. After researching more, there are some cons to this setup if you plan on having more advanced light setups. For me and my floor lamp, it's just perfect.I highly recommend it and will buy an Echo dot for my bedroom now."

Comment  Read more