Skip to content

Commit

Permalink
añadidos resultados finales
Browse files Browse the repository at this point in the history
  • Loading branch information
J0hnG4lt committed Mar 21, 2017
1 parent 9d6c1f3 commit 264a46a
Show file tree
Hide file tree
Showing 2 changed files with 305 additions and 9 deletions.
49 changes: 40 additions & 9 deletions hacerPrediccion.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from weka.filters import Filter, MultiFilter
from extractor_de_features import Tweet,TweetFeatureExtractor


# Fuentes:
# https://github.com/fracpete/python-weka-wrapper-examples/blob/master/src/wekaexamples/classifiers/output_class_distribution.py
# http://pythonhosted.org/python-weka-wrapper/examples.html
Expand Down Expand Up @@ -86,7 +87,7 @@ def detectarSpam_(tuitsConDatos,modeloFilename) :
status["retweet_count"])
vectores.append(vector)

ifileName = "tweets/predictMe.csv"
ifileName = "predictMe.csv"
#modelFilename = "tweets/modelos/naivebayes.model"
#modelFilename = "tweets/modelos/usado_en_interfaz_knn.model"

Expand Down Expand Up @@ -138,7 +139,7 @@ def construirFeature(tweetText, tweet_id,favorite_count,retweet_count) :
featureVector = extractor.getFetureVector()
featureVector["tweet_id"] = tweet_id
featureVector["topic_id"]=idTopico
featureVector["spam"] = 'n' if tweet_id % 2 else 'y'
featureVector["spam"] = 'n' if int(tweet_id) % 2 else 'y'
return featureVector


Expand Down Expand Up @@ -189,24 +190,54 @@ def predictWithWeka(csvFilenameWithInputToPredict,modelFilename):
result["distribution"] = str(dist.tolist())

results.append(result)
print result
#print result

return results

def main() :

input_file = csv.DictReader(open("datasets/dumpCNNEE_APLICACION.csv", "r"))
tuits = []
ids = []
for row in input_file :
tuit = dict()
tuit["tweetText"] = row["text"]
tuit["tweet_id"] = row["id"]
tuit["favorite_count"] = row["favorite_count"]
tuit["retweet_count"] = row["retweet_count"]
tuits.append(tuit)
ids.append(row["id"])

ifileName = "predictMe.csv"
modelFilename = "naivebayes.model"
out = predictWithWeka(ifileName,modelFilename)
print out
modeloFilename = "naivebayes.model"

predicciones = detectarSpam(tuits,modeloFilename)

out = open("resultadosCNNEE_APLICACION.csv","w")
out.write("tweet_id,distribution1,distribution2,predicted\n")
for indx,tweet_id in enumerate(ids) :
out.write(str(tweet_id))
out.write(",")
distribution = ast.literal_eval(predicciones[indx]["distribution"])
out.write(str(distribution[0]))
out.write(",")
out.write(str(distribution[1]))
out.write(",")
out.write(str(predicciones[indx]["predicted"]))
out.write("\n")
out.close()



if __name__ == "__main__":
import ast
import csv
try:
jvm.start()
jvm.start(system_cp=True, packages=True)
#jvm.start()
#jvm.start(system_cp=True, packages=True)
main()
except Exception, e:
print(traceback.format_exc())
finally:
jvm.stop()
#jvm.stop()
pass
265 changes: 265 additions & 0 deletions resultadosCNNEE_APLICACION.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
tweet_id,distribution1,distribution2,predicted
11557,1.0,1.33607579241e-141,n
10949,0.0575524197802,0.94244758022,y
10951,0.0836928000007,0.916307199999,y
13949,0.0504259017283,0.949574098272,y
14110,0.746756529818,0.253243470182,n
13950,0.161513942686,0.838486057314,y
10952,0.0993045846504,0.90069541535,y
10953,0.184692731536,0.815307268464,y
10954,0.118294011577,0.881705988423,y
13953,0.421468904786,0.578531095214,y
10955,0.0735811758029,0.926418824197,y
10950,0.0585132002034,0.941486799797,y
10956,0.089099832616,0.910900167384,y
10957,0.0757608782336,0.924239121766,y
13955,0.107123871558,0.892876128442,y
14111,0.0975605972912,0.902439402709,y
11102,0.637850728951,0.362149271049,n
13952,0.177353302537,0.822646697463,y
11107,0.999357928118,0.000642071882115,n
13951,0.457938788209,0.542061211791,y
13956,0.221189280139,0.778810719861,y
10960,0.167234986221,0.832765013779,y
10961,1.0,2.94684840409e-13,n
10958,0.19029581099,0.80970418901,y
14420,0.583346076708,0.416653923292,n
13957,0.00900623273854,0.990993767261,y
11307,0.0925296196221,0.907470380378,y
10959,0.98998141325,0.0100185867504,n
14074,0.334795076915,0.665204923085,y
13958,0.0654957814779,0.934504218522,y
10963,0.999999999999,9.20159846627e-13,n
10964,0.459552794182,0.540447205818,y
10962,1.0,8.74706364017e-16,n
13954,0.0708300309353,0.929169969065,y
10965,1.0,5.00202794182e-20,n
10967,0.565537206226,0.434462793774,n
13960,0.0991036345982,0.900896365402,y
10968,0.999999999884,1.16272475569e-10,n
13959,0.504130720183,0.495869279817,n
10969,0.769492021794,0.230507978206,n
10966,0.999999999994,6.05249820718e-12,n
10970,1.0,1.25369034846e-76,n
13961,0.0362899762697,0.96371002373,y
10971,0.144825121678,0.855174878322,y
10972,1.0,5.14821032981e-78,n
13962,0.120442817533,0.879557182467,y
10974,0.999033393483,0.00096660651728,n
10975,1.0,8.10642545667e-16,n
13963,0.683875247519,0.316124752481,n
13964,0.193737170409,0.806262829591,y
10976,1.0,1.07052614926e-73,n
14081,0.120471974134,0.879528025866,y
13965,0.121760417193,0.878239582807,y
10980,0.11549820548,0.88450179452,y
10978,0.946892877761,0.0531071222387,n
10977,0.999999993192,6.80768162707e-09,n
10973,0.0969891798321,0.903010820168,y
11377,0.999986836574,1.3163425628e-05,n
11094,0.999999957077,4.2922919732e-08,n
10981,0.978624428477,0.0213755715227,n
10979,0.259659874759,0.740340125241,y
10983,0.982401841607,0.0175981583931,n
10982,0.998334274297,0.0016657257026,n
11420,0.231921712858,0.768078287142,y
13967,0.243279327883,0.756720672117,y
10986,0.999081698976,0.00091830102367,n
10984,0.967403944475,0.0325960555251,n
13966,0.0861266803118,0.913873319688,y
10985,0.985289351842,0.0147106481585,n
13969,0.907960558072,0.0920394419284,n
10988,0.985686910401,0.0143130895986,n
10987,0.0933907235366,0.906609276463,y
13970,0.999999999318,6.82046997117e-10,n
10990,0.330100681856,0.669899318144,y
10989,0.12180276063,0.87819723937,y
10992,0.0985356263639,0.901464373636,y
10991,0.999999753434,2.46565941099e-07,n
10993,0.0985695558083,0.901430444192,y
13972,0.999983167426,1.68325740441e-05,n
10994,0.723596095362,0.276403904638,n
13968,0.0810552967707,0.918944703229,y
10995,0.999869710813,0.000130289186778,n
10997,0.0238437155701,0.97615628443,y
10996,0.999793048528,0.000206951471976,n
13975,0.107470697236,0.892529302764,y
13976,0.854486874535,0.145513125465,n
11000,0.963829195722,0.0361708042777,n
13973,0.0942924355136,0.905707564486,y
13977,0.562131421406,0.437868578594,n
13974,0.301438339546,0.698561660454,y
11001,0.184025586142,0.815974413858,y
11002,0.200407376185,0.799592623815,y
13971,0.720230692313,0.279769307687,n
11431,0.149451410875,0.850548589125,y
11003,0.999999999977,2.3298182122e-11,n
11004,0.137689773505,0.862310226495,y
10998,0.467120172518,0.532879827482,y
11005,0.758688268717,0.241311731283,n
13979,0.985314477849,0.0146855221514,n
11008,0.999999992641,7.35883401439e-09,n
11006,0.305925693284,0.694074306716,y
10999,0.196880809297,0.803119190703,y
11007,0.999999999956,4.37634219821e-11,n
13980,0.986826337552,0.0131736624482,n
11009,0.106723899285,0.893276100715,y
11010,0.0797734379257,0.920226562074,y
11013,0.151180973017,0.848819026983,y
11011,0.869702323104,0.130297676896,n
11014,1.0,6.04088399834e-15,n
11012,0.163802161271,0.836197838729,y
13982,0.982642037071,0.0173579629289,n
13983,0.93582362958,0.0641763704197,n
13984,0.97143980686,0.0285601931404,n
11017,0.159375894119,0.840624105881,y
13978,0.978140762094,0.0218592379063,n
11018,0.0446873222233,0.955312677777,y
11015,1.0,2.47374086451e-76,n
11016,0.161775509332,0.838224490668,y
11024,0.235480332202,0.764519667798,y
11029,0.789323492989,0.210676507011,n
11032,0.0882304597947,0.911769540205,y
11034,0.093841987781,0.906158012219,y
11039,0.0806902943371,0.919309705663,y
11041,0.0560525312633,0.943947468737,y
11042,0.0837141650777,0.916285834922,y
11046,0.0777727177681,0.922227282232,y
11049,0.0537160845607,0.946283915439,y
11051,0.112213762036,0.887786237964,y
11053,0.104464330744,0.895535669256,y
11057,0.0837664555043,0.916233544496,y
11055,0.0809555931863,0.919044406814,y
11061,0.0910422275027,0.908957772497,y
11064,1.0,1.54739758386e-78,n
11066,1.0,2.6947967209e-76,n
11070,0.897855571848,0.102144428152,n
11073,0.999940733749,5.92662506235e-05,n
11074,0.999999999935,6.53116337463e-11,n
11078,0.87724164474,0.12275835526,n
11082,0.979493925337,0.0205060746631,n
11085,0.999999999665,3.34657736388e-10,n
11087,0.999999821085,1.78914846482e-07,n
11019,0.199890306892,0.800109693108,y
11021,0.313045415992,0.686954584008,y
11025,0.129999719863,0.870000280137,y
11030,0.996823234768,0.00317676523155,n
11022,0.999999870138,1.29862323574e-07,n
11028,0.10240862027,0.89759137973,y
11033,0.70512207016,0.29487792984,n
11035,0.162223262757,0.837776737243,y
11037,0.999999999815,1.85364398427e-10,n
11040,0.0875992923919,0.912400707608,y
11044,0.0993565678,0.9006434322,y
11045,0.0872507075979,0.912749292402,y
11047,0.995481326332,0.00451867366824,n
11050,0.0820749540067,0.917925045993,y
11058,0.122353273986,0.877646726014,y
11056,0.397856679303,0.602143320697,y
11063,0.699379397033,0.300620602967,n
11065,0.140913600371,0.859086399629,y
11067,1.0,3.3157248005e-72,n
11072,0.995373446964,0.00462655303566,n
11068,0.102662696606,0.897337303394,y
11071,0.999997153172,2.84682838832e-06,n
11077,1.0,7.66375281081e-76,n
11081,1.0,1.97622366792e-131,n
11080,1.0,5.6846523309e-75,n
11086,0.999999995388,4.61247260506e-09,n
11089,1.0,1.00697754698e-78,n
11091,1.0,5.8251514294e-18,n
11093,1.0,1.73753014394e-82,n
11095,1.0,6.9762916962e-75,n
11020,0.12214316814,0.87785683186,y
11023,0.0929562913019,0.907043708698,y
11026,0.154903587809,0.845096412191,y
11027,0.317333333626,0.682666666374,y
11031,0.112530232743,0.887469767257,y
11036,0.080434880458,0.919565119542,y
11038,0.0924400222937,0.907559977706,y
11043,0.112102987247,0.887897012753,y
11048,0.0521978629875,0.947802137013,y
11054,0.106183854949,0.893816145051,y
11052,0.145315324884,0.854684675116,y
11059,0.0737302455764,0.926269754424,y
11060,0.432451126178,0.567548873822,y
11062,0.607807178768,0.392192821232,n
11069,0.995053598699,0.00494640130083,n
11075,0.555466593608,0.444533406392,n
11076,1.0,3.81138240219e-18,n
11079,0.990381960341,0.00961803965909,n
11083,0.808259671339,0.191740328661,n
11084,1.0,6.86457422377e-17,n
11092,1.0,1.04720341576e-78,n
11090,0.999999994412,5.58805281318e-09,n
11088,1.0,8.1868375593e-84,n
11096,0.873616494672,0.126383505328,n
11097,0.917865438668,0.0821345613317,n
11099,0.0874872762513,0.912512723749,y
11098,0.922369485054,0.0776305149465,n
11100,0.811090935316,0.188909064684,n
11101,0.892652530941,0.107347469059,n
11104,1.0,5.06111991558e-122,n
11103,0.103953826609,0.896046173391,y
11434,0.794063043876,0.205936956124,n
13985,0.949057742461,0.0509422575388,n
11106,0.234034539954,0.765965460046,y
11112,0.497113038291,0.502886961709,y
11114,0.998981422445,0.00101857755535,n
11109,0.288030893709,0.711969106291,y
11117,0.196615971702,0.803384028298,y
11118,0.183607296591,0.816392703409,y
11121,1.0,1.0370860167e-75,n
11119,0.195799184835,0.804200815165,y
11128,0.999804043192,0.000195956807931,n
11130,0.999856028654,0.00014397134582,n
11132,0.764678253766,0.235321746234,n
11134,0.99999999484,5.16043577402e-09,n
11136,0.273416010282,0.726583989718,y
11138,0.837858883521,0.162141116479,n
11140,0.360022709129,0.639977290871,y
11145,0.975234393707,0.0247656062926,n
11147,0.115193823832,0.884806176168,y
11149,0.940670298095,0.0593297019049,n
11154,0.99896995279,0.00103004720993,n
11157,0.788766659023,0.211233340977,n
11158,0.081351095653,0.918648904347,y
11160,0.999993011243,6.98875745763e-06,n
11162,0.999999967584,3.24163526685e-08,n
11166,0.999578420234,0.000421579765914,n
11174,0.958651126975,0.0413488730253,n
11176,0.362800304208,0.637199695792,y
11181,0.745075888206,0.254924111794,n
11186,0.838342245391,0.161657754609,n
11184,0.999904293197,9.57068033017e-05,n
11192,0.975778014382,0.0242219856179,n
11193,0.881849188443,0.118150811557,n
11197,0.883614836441,0.116385163559,n
11200,0.682668381717,0.317331618283,n
11438,0.999999999939,6.09502708212e-11,n
11105,0.210094500315,0.789905499685,y
13981,0.973436315834,0.0265636841661,n
11108,0.171903033736,0.828096966264,y
11111,0.99854091949,0.00145908051016,n
11115,0.999999999551,4.48622278903e-10,n
11110,0.238685939421,0.761314060579,y
11116,0.274834022862,0.725165977138,y
11124,0.999999999722,2.77627156989e-10,n
11120,0.741889214191,0.258110785809,n
11127,0.999899584651,0.000100415349233,n
11133,0.997022973337,0.00297702666349,n
11135,0.802188678469,0.197811321531,n
11137,1.0,1.0185617611e-16,n
11142,0.400228055635,0.599771944365,y
11144,0.999511312953,0.000488687046834,n
11148,0.176669777917,0.823330222083,y
11146,1.0,2.58283795748e-15,n
11150,0.225195149574,0.774804850426,y
11153,0.0818787859818,0.918121214018,y
11156,0.526960063618,0.473039936382,n
11159,0.316345132478,0.683654867522,y
11164,1.0,1.43449422117e-80,n
11167,0.999935142904,6.48570959468e-05,n
11171,1.0,4.79163902136e-76,n
11173,0.882628585538,0.117371414462,n
11177,0.282004436536,0.717995563464,y

0 comments on commit 264a46a

Please sign in to comment.