Escolar Documentos
Profissional Documentos
Cultura Documentos
client_1dd3315126b3445ba13ee3de57612bf2 = ibm_boto3.client(service_name='s3',
ibm_api_key_id='HRUzrUczp7wFf7hBHgUwQgEaXwrdJqcNo8r0ijWiimK5',
ibm_auth_endpoint="https://iam.bluemix.net/oidc/token",
config=Config(signature_version='oauth'),
endpoint_url='https://s3.eu-geo.objectstorage.service.networklayer.com')
body = client_1dd3315126b3445ba13ee3de57612bf2.get_object(Bucket='rainfallprediction-don
otdelete-pr-qac5ghq4uqv4bj',Key='final-dataset.csv')['Body']
# add missing __iter__ method, so pandas accepts body as file-like object
if not hasattr(body, "__iter__"): body.__iter__ = types.MethodType( __iter__, body )
df = pd.read_csv(body)
df.head()
Out[17]:
temp temp DP DP humidity SLP visibility
year month day tempavg DPavg ... SLPavg
high low high low high low high
5 rows × 23 columns
In [18]: df.head()
Out[18]:
temp temp DP DP humidity SLP visibility
year month day tempavg DPavg ... SLPavg
high low high low high low high
5 rows × 23 columns
In [19]: df.drop(["A"],axis=1,inplace=True)
df.drop(["b"],axis=1,inplace=True)
df.drop(["temp high"],axis=1,inplace=True)
df.drop(["temp low"],axis=1,inplace=True)
df.drop(["visibilityavg"],axis=1,inplace=True)
df.drop(["DP high"],axis=1,inplace=True)
df.drop(["DP low"],axis=1,inplace=True)
df.drop(["humidity high"],axis=1,inplace=True)
df.drop(["SLP high"],axis=1,inplace=True)
df.drop(["SLP low"],axis=1,inplace=True)
df.drop(["humidity low"],axis=1,inplace=True)
df.drop(["wind high"],axis=1,inplace=True)
df.drop(["visibility high"],axis=1,inplace=True)
#df.drop(["SLP avg"],axis=1,inplace=True)
#df.drop(["visibility low"],axis=1,inplace=True)
In [55]: df.head()
Out[55]:
year month day tempavg DPavg humidity avg SLPavg visibilitylow windavg Rainfall
In [21]: df.isnull().any()
In [22]: x=df.iloc[:,3:9].values
In [23]: y=df.iloc[:,9].values
In [24]: x
In [27]: x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=0)
In [28]: x_train
In [29]: y_train
In [30]: x_test
In [32]: mlr=LinearRegression()
In [33]: mlr.fit(x_train,y_train)
In [34]: y_pred=mlr.predict(x_test)
In [35]: y_pred
Out[35]: array([ 3.38759607, 6.36666643, 6.23912028, 7.99437554,
-4.12204175, 3.36878279, 0.67930045, 5.32868189,
-0.07123403, 0.98144609, 3.52235072, -0.1249315 ,
3.43030437, 3.87767851, 8.58714519, 3.57169665,
1.78510611, 2.9379245 , 0.77287268, -1.23863666,
-0.30046977, -2.00280891, 0.25002615, 5.22567406,
0.38969298, 2.69733689, 1.94386123, -0.71475882,
1.75564883, 1.24554724, 12.49482796, 3.82350061,
-3.38520785, 3.02021826, 2.5528487 , 9.36405054,
-0.57229348, -0.78703655, 1.766801 , 3.49459723,
1.41172939, -2.03857537, 3.84203478, -0.96390209,
-1.08489785, 1.26429088, 3.47308493, -0.03758404,
1.23495678, 5.01153584, 2.11831085, 2.15966804,
0.51327553, 6.0679404 , 0.4935252 , -1.7170277 ,
2.87408157, 8.58463264, 3.24349776, -0.08043386,
2.21390298, 0.32027489, 1.60563103, 2.42945963,
2.64921808, 2.2821146 , -0.54866465, -0.67225936,
-0.58236355, 2.89958489, 2.79112403, 4.65396102,
6.17623243, 2.76842645, 7.34439653, 1.07312259,
1.30039354, 2.64692283, -0.69461567, -0.45476529,
-3.46053904, -3.76629377, -0.47677361, 1.2277714 ,
1.99473737, 1.0197857 , 8.89958677, 0.90117223,
3.20870155, -1.37845702, -1.41086805, -0.60962283,
1.83110959, 0.43454391, -1.74972622, -0.75896364,
-0.90541068, -0.13853245, 1.59825804, 5.29518877,
1.48581236, 1.26642262, 2.19323356, -1.72847975,
-0.02615596, 1.12206782, 6.40144742, -0.69932558,
0.83919759, 0.44874652, 3.72238851, -0.32317445,
3.68760414, 1.85082034, 2.3643502 , -0.04104266,
1.734635 , 3.99064758, 4.63356757, 0.672562 ,
2.8095803 , -1.27499576, 5.57668244, 3.41706305,
-0.35485959, 5.94668814, 3.01575608, 1.01940683,
1.04510095, 0.07757075, -0.15168028, 4.17061761,
-2.28435113, -1.27322759, 2.75816525, 1.44290429,
0.76129995, 1.4587097 , 3.95326306, -1.47419694,
-0.73492321, 1.81818218, 5.231854 , 0.04604856,
1.72548326, 4.25103099, 3.41155836, 0.53496994,
1.48155232, 8.76713939, 1.01272306, -1.18160488,
-0.68535911, 2.00698402, -0.5618786 , 6.00037973,
1.90874991, 1.28338833, 2.52499665, 0.19580336,
3.91172796, 0.37504229, 0.09749899, 0.97341 ,
2.20173761, -0.04893289, -0.22403027, 1.91928526,
2.55235612, 0.1745984 , 0.93704188, -2.98044232,
4.33570315, -1.11342388, -0.88354701, -2.19865423,
8.59103532, 3.14903419, 3.38791118, -2.31023831,
1.53395303, -2.03976065, -0.14693399, 1.42009806,
2.09462786, -0.18758319, 1.14517044, 8.07963734,
0.79168595, 1.46532986, 2.11739765, 5.06668398,
4.68128448, 1.32616232, -1.33460051, -3.28067665,
-0.37561348, 2.85152356, 1.39436173, 1.44647507,
1.34636064, 1.77463413, 4.48385817, 2.4394453 ,
0.50254356, 3.34244875, -1.13939271, 6.42993193,
2.87226838, 0.02293078, -0.77209275, 3.45957153,
0.48247894, -0.91362455, 2.50276434, 0.07934243,
-0.80974929, 6.49742341, -0.78829999, 2.87023013,
0.03162201, 0.92089482, 2.8665968 , 1.63372266,
2.86318077, 1.09479282, -1.40752435, 0.21236373,
1.08786976, 0.0912049 , 2.64143336, 3.75724176,
1.51935953, -0.32620925, 1.3743753 , -0.42673534,
1.22334567, 7.64313471, -0.30782561, 8.76079376,
0.13221729, 2.13980907, 2.47530825, -0.42600631,
1.93245419, -1.85455375, 1.58068748, -2.01841098,
1.15403092, 6.13082825, 4.54151228, 0.84258382,
-0.25187918, 1.96723519, 2.90020527, 8.90085327,
1.44882066, 3.55651476, -0.30722715, 1.23316752,
0.97115202, 1.62220147, 3.82063777, 1.47152732,
5.55752475, 3.1392816 , 5.20543747, 1.88738828,
1.98324586, -1.63392819, 1.03402464, 2.55953054,
2.62046441, 2.22608057, 4.07233847, 0.7563003 ,
-1.34938287, -0.47424697, -0.08864465, -2.27425368,
1.20499254, 1.29438369, 1.12629379, 1.99486673,
-0.1181683 , 0.21098525, 5.76458643, 1.11814911,
-0.84631723, 5.32994545, -0.03090232, 10.22681019,
-0.23797602, 1.2654371 , 1.93644216, -4.60969911,
10.1634998 , -1.85410064, -1.47264606, 5.00207056,
-1.3422097 , 4.06667003, -3.91953956, 2.70046267,
0.15180419, 0.73270466, 3.55701092, -0.90077311,
1.90734069, -1.96949982, 1.40480633, 0.55134613,
-2.02901346, 4.8698351 , 1.08279082, 3.04111988,
7.91532349, 6.96554236, 2.09615982, 3.71609762,
0.66830509, 3.11679792, 1.24956794, 7.57268927,
1.80844488, 1.9732669 , -0.36694956, 9.35515053,
2.27611884, 2.21984358, -0.55144302, 1.22903804,
2.97379415, -2.05043233, 1.87017428, 0.03199065,
1.35176564, 3.79499493, 1.18030792, 7.60459533,
0.97015434, 1.21729643, 3.45929599, 2.27585338,
-2.88218047, 2.6780705 , -0.172603 , 0.23103428,
3.63587536, 2.49318722, -0.42701951, -0.64974938,
2.53479771, 0.94427335, -0.56573004, 0.50946662,
3.39906021, -0.30507461, 2.11038121, 3.16428877,
3.42245603, 8.89443864, 0.51643776, -0.60902122,
-1.33054931, 12.85106896, 3.48253813, 1.66822248,
0.70187775, 1.3382191 , 1.12501507, 1.33767487,
1.7988157 , -1.45464323, 5.13623137, -2.56323339,
0.72531846, -1.27913725, 3.43905934, 2.0790561 ,
-3.22958867, 5.34845645, 0.91614852, 3.97658954,
0.52733344, 5.14799721, 6.20669389, 6.01506546,
-0.49407515, 1.85189341, 2.26617313, 5.12466172,
2.80416009, 0.33758852, -1.25496784, -1.70507731,
1.6227789 , 1.53907705, 0.42876318, 2.40307047,
-2.23434216, 1.55396567, 0.48381475, 2.08867819,
2.20390216, 4.00386467, 3.59734269, 0.69808955,
9.16037522, 0.15023542, 3.33010547, 0.39068746,
-0.19696405, 3.45482523, -1.37828814, -2.65652452,
2.65377663, 2.46302201, 1.5335019 , 3.63241994,
-2.68164704, -4.18557928, -0.8084464 , -0.16749119,
0.43273585, 4.52801766, 3.39171653, -0.93455046,
-0.4318593 , 4.01397419, 0.83859593, 1.99013253,
7.93658869, 0.5788264 , 2.76335953, 1.39458259,
4.25851262, -1.65315163, 1.11224804, -0.6434695 ,
0.10870621, 1.75397687, -1.47087784, -1.17994856,
1.25136698, 2.68435237, 2.26037511, 9.64171112,
5.79950881, 0.60043287, 2.71860203, 0.57458827,
1.15207821, -0.18696631, 0.17039667, 1.21818226,
-2.01961744, 1.04878933, 1.1652382 , 1.70261365,
2.01420347, 3.66444128, 1.11034335, 2.59723442,
2.87990488, 2.02040639, 8.65378044, 0.80348786,
1.28019836, 0.14322481, -1.40501506, 1.6633378 ,
2.7664495 , 1.53247455, 9.71323545, 2.79331282,
2.4201601 , 4.88903224, 4.32485588, 3.37570586,
1.55977577, 1.82057072, 0.76569632, -0.33866474,
-1.42024304, 5.4347249 , 2.56036478, 1.47249757,
-0.83395561, 3.22090024, -2.06158136, 9.78471489,
0.6933432 , 3.58245593, 1.88795312, 3.37230554,
4.26851344, 2.0849354 , 1.58383449, 5.61793964,
5.36226299, 2.16788198, -2.59723169, 2.47667808,
0.74028962, 3.99085835, 2.27371307, 0.26117831,
7.45498907, 5.3941296 , 3.86423742, 1.82424358,
0.66341415, 0.78841814, 1.60933781, 6.76255312,
-1.73467684, 0.377219 , 4.73880915, -2.63368428,
-0.55501924, 1.51900923, 0.08300318, 2.54718727,
3.24691173, 5.44111542, -1.36770081, 1.71502932,
-3.33630565, 5.72047862, 1.11220851, -2.89050656,
3.61818113, -0.49273626, 6.20747659, 0.48868542,
-0.21743091, 1.57783685, 5.69946478, 3.99209218,
1.52445367, 3.92718231, 3.8277207 , 7.66273682,
2.29026121, 4.77661636, 4.54669441, 5.75183142,
-2.28230493, -0.54912673, 2.68971554, 0.38201344,
-0.80740064, -1.44723931, 3.97452826, 0.7321601 ,
2.36283519, -0.10159592, -2.1742511 , 3.92755997,
0.22621873, 1.39607322, 0.22521842, 1.92057613,
4.91439284, -1.16264701, 6.82767477, -1.20275798,
2.35854509, 7.21158364, 1.83311033, 2.49566024,
3.38990334, -0.20870567, 1.06486927, 0.55909991,
-1.19011832, -2.0153641 , -1.78145432, 5.73216005,
5.63885014, 5.08269466, 3.7551233 , 1.61565608,
3.52598405, 0.87064151, 1.00159826, 4.67221216,
4.28177662, 2.74163225, -1.18497915, 0.64740347,
3.0589507 , -0.24924936, -2.71828173, 3.72286894,
1.2525336 , 4.91836865, 0.06778485, -0.82060207,
3.77468589, 2.86454089, 2.61202348, -2.08453921,
7.02740165, -0.93635852, 1.27515567, 0.50223515,
1.24181729, 3.95228059, 3.75223272, -1.14006991,
2.40631398, -1.64328132, -3.13896375, -1.6213422 ,
2.31726111, 3.96702777, -0.73826371, 2.47799318,
3.4201378 , 0.63680099, 0.06726766, 2.12131328,
1.3423606 , 2.30596034, -0.92546285, 6.54020091,
0.48925928, 4.60911003, 4.11199632, 2.06053288,
1.77532026, -0.52046437, 4.31164443, -1.75249557,
2.08288919, 0.6458886 , 0.75037172, 4.42767253,
1.10085972, 2.21557152, 0.93711114, 1.50651108,
-0.39221679, 3.04097523, 0.02542811, 1.03141867,
1.2214289 , 3.27759612, 1.2654371 , 0.87992895,
1.21992312, 4.69847738, -0.67148568, 4.06037286,
0.68453662, -1.45194927, 4.89601234, 0.08756844,
3.11041942, 2.14301318, -0.03632253, 2.19743023,
1.17824337, 8.19676012, 2.8297599 , 6.07190406,
1.40959872, 6.65997769, 4.11696681, 5.46018869,
2.44816625, 2.12695762, 3.0996875 , 1.27280106,
-1.72669586, 7.28612868, 5.95864487, 4.62929551,
3.05444562, 2.47705574, 1.94015088, 2.67871116,
3.20194231, 3.75092356, 2.28062391, 1.86527112,
-0.58544131, 2.91229174, -2.01793369, 4.38562406,
-0.82595002, -1.75900458, 1.11389221, -1.08901524,
2.39856226, -2.03138999, 2.4701449 , 0.5230402 ,
-1.57117331, 8.18854619, 0.83168509, 0.10357911,
3.05151946, 2.19809213, -0.20989997, 4.30526004,
-1.02437401, 6.65989328, -1.2508986 , 1.33260795,
-1.6388192 , -0.80322821, -0.67338135, 6.07465155,
4.51357539, 1.27147432, 4.46946757, 2.54306874,
-0.10148371, -0.51950608])
In [36]: mlr.intercept_
Out[36]: 316.19992552911049
In [37]: mlr.coef_
In [39]: r2_score(y_test,y_pred)
Out[39]: 0.1163989252024541
In [40]: df.corr()
Out[40]:
humidity
year month day tempavg DPavg SLPavg visibilitylow
avg
humidity
-0.022888 0.327681 0.030402 0.349759 0.743077 1.000000 -0.584092 0.149500
avg
/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/sklearn/cross_validation.py:4
1: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model
_selection module into which all the refactored classes and functions are moved. Also n
ote that the interface of the new CV iterators are different from that of this module.
This module will be removed in 0.20.
"This module will be removed in 0.20.", DeprecationWarning)
2019-05-23 09:43:11,507 - watson_machine_learning_client.metanames - WARNING - 'AUTHOR_
EMAIL' meta prop is deprecated. It will be ignored.
In [45]: wml_credentials = {
"username": "cf43da35-0ce4-4edb-a106-02fc4fb042b8",
"password": "5c83964d-5dda-4f53-ab1f-40ac25f3ac0a",
"instance_id": "90f9eaf2-9a60-4712-b10d-23315d3a042c",
"url" : "https://eu-gb.ml.cloud.ibm.com"
}
In [49]: client.repository.list_models()
In [51]: published_model_uid
Out[51]: '3bb6d31f-e18c-4bd6-b2c4-72d02bff5ce9'
In [52]: deployment = client.deployments.create(published_model_uid,name="final project")
#######################################################################################
#######################################################################################
INITIALIZING
DEPLOY_SUCCESS
---------------------------------------------------------------------------------------
---------
Successfully finished deployment creation, deployment_uid='ff138a13-247f-41ae-a0b8-202c
bfd1d7e7'
---------------------------------------------------------------------------------------
---------
In [54]: scoring_endpoint
Out[54]: 'https://eu-gb.ml.cloud.ibm.com/v3/wml_instances/90f9eaf2-9a60-4712-b10d-23315d3a042c/d
eployments/ff138a13-247f-41ae-a0b8-202cbfd1d7e7/online'