<jupyter_start><jupyter_text>LabeledVector(0.0, DenseVector(0.0012, -2.0E-4, 0.722891566265067, 0.663396555482886, 0.800641458474005, 1.0, 0.212560386473422, 0.530303030303009))<jupyter_code>from time import time
from scipy import sparse
from scipy import linalg

from sklearn.datasets.samples_generator import make_regression
from sklearn.linear_model import Lasso

X, y,ws = make_regression(n_samples=160359, n_features=7, random_state=0,coef=True)

print(ws)
with open('ALSTest.csv',"w") as f:
    for x,sy in zip(X,y):  
        line = "LabeledVector("+str(sy)+", DenseVector("+", ".join(str(s) for s in x)+"))"
        #print(line)
        f.write(line+"\n")
!pwd
Right((WeightVector(DenseVector(96.68812577807105, 81.38285091205456, 99.97901751995805, 96.8509830269779, 83.23526316636055, 24.567420177941294, 38.6741822683018),-0.10012557740802042),160000))

print(ws)
import numpy as np
from sklearn.linear_model import LinearRegression

# make some data:
x1 = np.array(np.random.rand(5))
x2 = np.array(np.random.rand(5))
# stack together - to use as input
x = np.column_stack((x1,x2))
# create targets TRUE relationship
y = np.array(2*x1 - 0.5*x2)

# create & fit model...
k = LinearRegression()
k.fit(x,y)

# show the fitted weights
print(k.coef_)

# change weights to be 0 for nonzeros...
k.coef_ = [np.max([c,0]) for c in k.coef_]

# show new weights:
print(k.coef_)
from sklearn.linear_model import Ridge
import numpy as np
n_samples, n_features = 10, 5
np.random.seed(0)
#y = np.random.randn(n_samples)
#X = np.random.randn(n_samples, n_features)
clf = Ridge(alpha=1.0)
clf.fit(X, y) 
print(ws)
clf.coef_
clf.coef_=ws
import numpy
clf.coef_=numpy.array([93.85995436365121, 75.8740922439522, 93.14740962115546, 82.05427636470665, 82.43138497344309, 18.763337972952787, 27.21616398926061])
clf.score(X, y)<jupyter_output><empty_output><jupyter_text>SVM test<jupyter_code>import string
count = 0
with open('SVM_resultWeights.24.12.txt',"r") as f:
    for line in f:  
        #print(line)
        row = str(line)
        if str(line).startswith('Left((LabeledVector('):
            row = str(line)
            row = row.replace('Left((LabeledVector(',"")
            rs = row.split(",",1)
            y = rs[0]
            x=rs[1]
            x=x.replace("DenseVector(","")
            x=x.split(")),",1)[0]
            print(np.array(x.split(","), dtype=np.float))
            print(len(row.split(",",1)))
            print(y)
            
        count+=1
        if count>4:
            break
        

from sklearn.svm import LinearSVC
from sklearn.datasets import make_classification
X, y = make_classification(n_samples=160359, n_features=7, random_state=0)
X.shape
from sklearn.svm import LinearSVC
from sklearn.datasets import make_classification
n_samples=160359
clf = LinearSVC(random_state=0)
clf.fit(X[:64996], y[:64996])
clf.score(X[64996:], y[64996:])
from sklearn.svm import LinearSVC
from sklearn.datasets import make_classification
X, y = make_classification(n_samples=160359, n_features=7, random_state=0)
X.shape
from sklearn.svm import LinearSVC
from sklearn.datasets import make_classification
#X, y = make_classification(n_features=4, random_state=0)
clf = LinearSVC(random_state=0)
clf.fit(X, y)


import string
count = 0 
correct = 0
with open('SVM_resultWeights.24.12.txt',"r") as f:
    for line in f:  
        #print(line)
        row = str(line)
        if str(line).startswith('Left((LabeledVector('):
            row = str(line)
            row = row.replace('Left((LabeledVector(',"")
            rs = row.split(",",1)
            y = rs[0]
            x=rs[1]
            x=x.replace("DenseVector(","")
            x=x.split(")),",1)[0]
            x = np.array(x.split(","), dtype=np.float)
            x = x.reshape(1, -1)
            #print(x)
            #print(len(row.split(",",1)))
            #print(y)
            #print(x.shape)
            ypred = clf.predict(x)
            
            y=y.strip()
            #print(y)
            y=float(y)
            y=int(y)
            if ypred[0]==0:
                ypred=-1
            else:
                ypred=1
                
            
            #print(type(y))
            #print(type(ypred))
            if y==ypred:
                correct +=1
                #print("y:{} ypred:{} correct:{}".format(y,ypred,correct))
    
        count+=1
        #if count>100:
        #   break
print("accuracy: {}%".format(1.0 * correct / count *100))
print("Num of testdata: {}".format(count))
#for xs ,ys in zip(X,y):
#    for xts, yts in zip(xt,yt):<jupyter_output>accuracy: 63.8531601944735%
Num of testdata: 64996
{'fraction_non_alphanumeric': 0.14653679653679655, 'fraction_numerical': 0.10238095238095238, 'mean_word_length': 2.860484544695071, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '597637', 'license': 'Apache-2.0', 'n_tokens_mistral': 2016, 'n_tokens_neox': 1736, 'n_words': 338, 'path': 'Sources/issuse18OnlineMLFlink/proteus-solma-development/src/main/resources/testDataGen2.ipynb', 'repo_name': 'zhanwangchen/Flink-online-machine-learning', 'size': '4620'}