<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 INDIA, G-20 AND THE WORLD - Statistical Year Book India 2016
 Navigation Path
Step1:  Data Cleanup
Step2:  Experiments
Step3:  Ideas
Show top 5 countries
Show only comparable countries
Step4:  IRIS Dataset
Step5:  Random Forest
Step6:  SVM
<ASSISTANT_TASK:>
Python Code:
%%sh
# ls -l ~/Downloads/G20*csv
# mv ~/Downloads/G20*csv G20.csv
Explanation: INDIA, G-20 AND THE WORLD - Statistical Year Book India 2016
 Navigation Path:  Home > Statistical Year Book India 2016 > INDIA, G-20 AND THE WORLD
The G20 (or G-20 or Group of Twenty) is an international forum for the governments and central bank governors from 20 major economies. It was founded in 1999 with the aim of studying, reviewing, and promoting high-level discussion of policy issues pertaining to the promotion of international financial stability.[3] It seeks to address issues that go beyond the responsibilities of any one organization.[3] The G20 heads of government or heads of state have periodically conferred at summits since their initial meeting in 2008, and the group also hosts separate meetings of finance ministers and central bank governors.
The members include 19 individual countries and along with the European Union (EU). The EU is represented by the European Commission and by the European Central Bank. Collectively, the G20 economies account for around 85% of the gross world product (GWP), 80% of world trade (or, if excluding EU intra-trade, 75%), and two-thirds of the world population.[2]
Data Source: 
* http://mospi.nic.in/statistical-year-book-india/2016/170
References:
* Wikipedia G20
Data Gathering
wget http://mospi.nic.in/statistical-year-book-india/2016/170
Country
Area
Population (Millions)
GDP Billions (USD)
Gross Domestic Product  Per Capita Income at Current Price  (USD)
Gross domestic product based on Purchasing-Power-Parity (PPP) valuation of Country GDP  in Billions ( Current International Dollar)
wget https://docs.google.com/a/imaginea.com/spreadsheets/d/1jbwyZsHy_SsJ-ANWlNVgMKOl5PkoMMcqkMiMJRXDXms/edit?usp=sharing
End of explanation
data = pd.read_csv('G20.csv')
cols = ['Area', 'Population_2010', 'Population_2011',
       'Population_2012', 'Population_2013', 'Population_2014',
       'Population_2015', 'GDP_2010', 'GDP_2011', 'GDP_2012', 'GDP_2013',
       'GDP_2014', 'GDP_2015', 'GDP_PCI_2010', 'GDP_PCI_2011', 'GDP_PCI_2012',
       'GDP_PCI_2013', 'GDP_PCI_2014', 'GDP_PCI_2015', 'GDP_PPP_2010',
       'GDP_PPP_2011', 'GDP_PPP_2012', 'GDP_PPP_2013', 'GDP_PPP_2014',
       'GDP_PPP_2015']
data[cols] = data[cols].applymap(lambda x: float(str(x).replace(',', '')))
all_countries = sorted(data.Country.unique())
country_labler = all_countries.index
# country_labler('India')
# data.Country = data.Country.map(country_labler)
sorted(data.columns.tolist())
cols1 = ['GDP_2010',
 'GDP_2011',
 'GDP_2012',
 'GDP_2013',
 'GDP_2014',
 'GDP_2015',]
cols2 = [
 'GDP_PPP_2010',
 'GDP_PPP_2011',
 'GDP_PPP_2012',
 'GDP_PPP_2013',
 'GDP_PPP_2014',
 'GDP_PPP_2015']
cols3 = []
data1 = data[['Area',
 'Country',
 'GDP_2010',
 'GDP_2011',
 'GDP_2012',
 'GDP_2013',
 'GDP_2014',
 'GDP_2015',]].copy()
data2 = data[['Area',
 'Country',
 'GDP_PPP_2010',
 'GDP_PPP_2011',
 'GDP_PPP_2012',
 'GDP_PPP_2013',
 'GDP_PPP_2014',
 'GDP_PPP_2015',]].copy()
data3 = data[['Area',
 'Country',
 'GDP_PCI_2010',
 'GDP_PCI_2011',
 'GDP_PCI_2012',
 'GDP_PCI_2013',
 'GDP_PCI_2014',
 'GDP_PCI_2015',]].copy()
data4 = data[['Area',
 'Country',
 'Population_2010',
 'Population_2011',
 'Population_2012',
 'Population_2013',
 'Population_2014',
 'Population_2015']].copy()
Explanation: Data Cleanup
End of explanation
import sklearn.cluster
clf = sklearn.cluster.AgglomerativeClustering(5)
pred = clf.fit_predict(data1['GDP_2010	GDP_2011	GDP_2012	GDP_2013	GDP_2014	GDP_2015'.split()])
pred
new_data.metric.unique()
new_data.head(20).copy(deep=True)
# segregating year & param
new_data['year'] = new_data.metric.map(lambda x: int(x.rsplit('_')[-1]))
new_data['param'] = new_data.metric.map(lambda x: ''.join(x.rsplit('_')[:-1]))
# drop metric column
new_data.drop('metric', axis=1, inplace=True)
# converting data into integers
# Key values to check how the world 
print('Country', new_data.country.unique())
print('Country', new_data.param.unique())
temp = new_data[(new_data.country == 'USA') & (new_data.param ==  'GDP')].copy(deep=True)
temp
X_Label = 'USA'
Y_Label = 'GDP'
plt.figure(figsize=(15, 5))
temp = new_data[(new_data.country == X_Label) & (new_data.param == Y_Label)].copy(deep=True)
_x,  _y = temp.year.values, temp.value.values
plt.plot(_x, _y)
plt.xticks(_x, map(str, _x))
X_Label = 'European Union'
Y_Label = 'GDP'
plt.figure(figsize=(15, 5))
temp = new_data[(new_data.country == X_Label) & (new_data.param == Y_Label)].copy(deep=True)
_x,  _y = temp.year.values, temp.value.values
plt.plot(_x, _y)
plt.xticks(_x, map(str, _x))
X_Label = 'USA'
Y_Label = 'GDP'
plt.figure(figsize=(15, 5))
temp = new_data[(new_data.country == X_Label) & (new_data.param == Y_Label)].copy(deep=True)
_x,  _y = temp.year.values, temp.value.values
plt.plot(_x, _y)
plt.xticks(_x, map(str, _x))
_y
_y - _y.min()
Y_Label = 'Population'
plt.figure(figsize=(15, 8))
all_countries = new_data.country.unique()[:5]
for X_Label in all_countries:
    temp = new_data[(new_data.country == X_Label) & (new_data.param == Y_Label)].copy(deep=True)
    _x,  _y = temp.year.values, temp.value.values
    _y = _y - _y.min()
    plt.plot(_x, _y)
    plt.xticks(_x, map(str, _x))
    
plt.legend(all_countries)
Explanation: Experiments
End of explanation
country_codes = {'Argentina': 'ARG',
 'Australia': 'AUS',
 'Brazil': 'BRA',
 'Canada': 'CAN',
 'China': 'CHN',
 'European Union': 'USA',
 'France': 'FRA',
 'Germany': 'DEU',
 'India': 'IND',
 'Indonesia': 'IDN',
 'Italy': 'ITA',
 'Japan': 'JPN',
 'Mexico': 'MEX',
 'Republic of Korea': 'USA',
 'Russia': 'RUS',
 'Saudi Arabia': 'SAU',
 'South Africa': 'ZAF',
 'Turkey': 'TUR',
 'USA': 'USA',
 'United Kingdom': 'GBR'}
chart_colors = ["rgb(0,0,0)",
"rgb(255,255,255)",
"rgb(255,0,0)",
"rgb(0,255,0)",
"rgb(0,0,255)",
"rgb(255,255,0)",
"rgb(0,255,255)",
"rgb(255,0,255)",
"rgb(192,192,192)",
"rgb(128,128,128)",
"rgb(128,0,0)",
"rgb(128,128,0)",
"rgb(0,128,0)",
"rgb(128,0,128)",
"rgb(0,128,128)",
"rgb(0,0,128)",]
chart_colors += chart_colors
chart_colors = chart_colors[:len(country_codes)]
data1['Country_Codes'] = data1['Country'].map(lambda x: country_codes[x])
import sklearn.cluster
clf = sklearn.cluster.AgglomerativeClustering(5)
pred = clf.fit_predict(data1['GDP_2010	GDP_2011	GDP_2012	GDP_2013	GDP_2014	GDP_2015'.split()])
pred
data1['cluster'] = pred
data1['text'] = 'Cluster ID' + data1.cluser
data1.head() 
import plotly.plotly as py
import pandas as pd
# df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_world_gdp_with_codes.csv')
data = [ dict(
        type = 'choropleth',
        locations = data1['Country_Codes'],
        z = data1['cluser'],
        text = data1['Country_Codes'],
#         colorscale = [[0,"rgb(5, 10, 172)"],[0.35,"rgb(40, 60, 190)"],[0.5,"rgb(70, 100, 245)"],\
#             [0.6,"rgb(90, 120, 245)"],[0.7,"rgb(106, 137, 247)"],[1,"rgb(220, 220, 220)"]],
#         autocolorscale = True,
#         reversescale = True,
#         marker = dict(
#             line = dict (
#                 color = 'rgb(180,180,180)',
#                 width = 0.5
#             ) ),
        colorbar = dict(
            autotick = False,
            tickprefix = '$',
            title = 'GDP<br>Billions US$'),
      ) ]
layout = dict(
    title = 'G-20"s GDP',
    geo = dict(
        showframe = False,
        showcoastlines = False,
        projection = dict(
            type = 'Mercator'
        )
    )
)
fig = dict(data=data, layout=layout)
# py.iplot( fig, validate=False, filename='d3-world-map' )
plot( fig, validate=False, filename='d3-world-map')
fig = {
    'data': [
  		{
  			'x': df2007.gdpPercap, 
        	'y': df2007.lifeExp, 
        	'text': df2007.country, 
        	'mode': 'markers', 
        	'name': '2007'},
        {
        	'x': df1952.gdpPercap, 
        	'y': df1952.lifeExp, 
        	'text': df1952.country, 
        	'mode': 'markers', 
        	'name': '1952'}
    ],
    'layout': {
        'xaxis': {'title': 'GDP per Capita', 'type': 'log'},
        'yaxis': {'title': "Life Expectancy"}
    }
}
data = []
year = 'GDP_2015'
data.append({
    'x': data1[year],
    'y': data1['cluster'],
    'mode': 'markers',
    'text': data1['Country'],
    'name': year,
    'colors': chart_colors
})
fig = dict(data=data, layout=layout)
# py.iplot( fig, validate=False, filename='d3-world-map' )
plot( fig, validate=False, filename='d3-world-map')
Explanation: Ideas
Show top 5 countries
Show only comparable countries
End of explanation
from sklearn import datasets
# import some data to play with
iris = datasets.load_iris()
X = iris.data # [:, :2]  # we only take the first two features.
Y = iris.target
X[:5]
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.25, random_state=0)
print(X_train.shape, y_train.shape, X_test.shape, y_test.shape)
from sklearn.metrics import accuracy_score
Explanation: IRIS Dataset
End of explanation
from  sklearn.ensemble import RandomForestClassifier
clf = RandomForestClassifier()
clf = clf.fit(X_train, y_train)
accuracy_score(clf.predict(X_train), y_train)
accuracy_score(clf.predict(X_test), y_test)
accuracy_score(clf.predict(X), Y)
Explanation: Random Forest
End of explanation
from sklearn import svm
clf = svm.SVC(kernel='linear', C=2)
clf = clf.fit(X_train, y_train)
accuracy_score(clf.predict(X_train), y_train)
accuracy_score(clf.predict(X_test), y_test)
accuracy_score(clf.predict(X), Y)
Explanation: SVM
End of explanation
<END_TASK>