Advertisement
Guest User

Untitled

a guest
Apr 12th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import MySQLdb
  2. import cgi
  3. import cgitb
  4. import pandas as pd
  5. import numpy as np
  6. from sklearn.cross_validation import train_test_split
  7. from sklearn import preprocessing, cross_validation, svm
  8. from sklearn.svm import SVR
  9. import mysql.connector as sql
  10. import pandas as pd
  11. cgitb.enable()
  12. print 'Content-type: text/htmlrnr'
  13. form = cgi.FieldStorage()
  14. e1= form.getvalue('EARNING_PER_SHARE', '')
  15. e2 = form.getvalue('CASH_INVESTMENT', '')
  16. e3 = form.getvalue('CURRENT_LIABILITY', '')
  17. e4 = form.getvalue('TOTAL_REVENUE', '')
  18. e5 = form.getvalue('GROSS_PROFIT', '')
  19. db = MySQLdb.connect(host="127.0.0.1", db="cisco", user="root", passwd="")
  20. cursor = db.cursor()
  21. cursor.execute("""
  22. INSERT INTO table1 (EARNING_PER_SHARE, CASH_INVESTMENT, CURRENT_LIABILITY,
  23. TOTAL_REVENUE,GROSS_PROFIT)
  24. VALUES (%s, %s, %s, %s, %s)
  25. """, (e1, e2, e3, e4,e5))
  26. db.commit()
  27. db.close()
  28. db_connection = sql.connect(host='127.0.0.1', database='cisco', user='root',
  29. password='')
  30. db_cursor = db_connection.cursor()
  31. db_cursor.execute('SELECT * FROM table1')
  32. table_rows = db_cursor.fetchall()
  33. df = pd.DataFrame(table_rows)
  34. np = df.as_matrix()
  35. X = df.drop([4], 1)
  36. np1 = X.as_matrix()
  37. y = df[4]
  38. np2 = y.as_matrix()
  39. x_train, x_test, y_train, y_test = train_test_split(np1, np2, test_size=0.3)
  40. clf = svm.SVR()
  41. clf.fit(np1, np2)
  42. confidence = clf.score(np1, np2)
  43. for k in ['rbf']:
  44. clf = svm.SVR(kernel=k, C=100, gamma=0.0001)
  45. clf.fit(np1, np2)
  46. confidence = clf.score(np1, np2)
  47. print(k,confidence)
  48. a = clf.predict(np1)
  49. print ('npredicted values')
  50. print (a)
  51. print ('nreal values')
  52. print (np2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement