SHARE
TWEET

Untitled

a guest Oct 4th, 2017 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
  53.    
  54. def fitness_function(a,x,np2,np1,C,gamma,):    
  55. C = x[0]
  56. gamma = x[1]
  57. clf = svm.SVR(kernel=k, C=10, gamma=0.0001,swarmsize=50)
  58. clf.fit(np1, np2)
  59. confidence = clf.score(np1, np2)
  60. print(k,confidence)
  61. mse = sqrt(mean_squared_error(np2, a))
  62. return mse
  63. lb = [10, 0.0001]
  64. ub = [1000,0.1]
  65. xopt, fopt = pso(fitness_function, lb, ub)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top