Posts

Showing posts with the label machine-learning

i am trying to classify certain articles as fake or real.by applying logistic regression i want to extract the percentage of veracity [on hold]

i am trying to classify certain articles as fake or real.by applying logistic regression i want to extract the percentage of veracity [on hold] clf = LogisticRegression(random_state=0) clf.fit(tidf_train, y_train) pred = clf.predict(tfidf_test) score = metrics.accuracy_score(y_test, pred) print("accuracy: %0.3f" % score) cm = metrics.confusion_matrix(y_test, pred, labels=['FAKE', 'REAL']) plot_confusion_matrix(cm, classes=['FAKE', 'REAL']) print(cm) This code gives me no error but doesnt produce the confusion matrix.Kindly suggest what might be wrong Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question. Hi, welcome to sta...

keras list of Numpy arrays not the size model expected

keras list of Numpy arrays not the size model expected I am having trouble finding the correct way of passing multiple inputs to a model. The model has 2 inputs (256, 256, 3) (256, 256, 3) and 1 output (256, 256, 3) I am producing the images via ImageDataGenerator : ImageDataGenerator x_data_gen = ImageDataGenerator( horizontal_flip=True, validation_split=0.2) And I am producing the samples via a python generator: def image_sampler(datagen, batch_size, subset="training"): for imgs in datagen.flow_from_directory('data/r_cropped', batch_size=batch_size, class_mode=None, seed=1, subset=subset): g_y = noises = bw_images = for i in imgs: # append to expected output the original image g_y.append(i/255.0) noises.append(generate_noise(1, 256, 3)[0]) bw_images.append(iu_rgb2gray(i)) yield(np.array([noises, bw_images]), np.array(g_y)) When trying to train the model with: gene...

Learning a Sin function

Image
Learning a Sin function I'm new to Machine Learning I' building a simple model that would be able to predict simple sin function sin I generated some sin values, and feeding them into my model. sin from math import sin xs = np.arange(-10, 40, 0.1) squarer = lambda t: sin(t) vfunc = np.vectorize(squarer) ys = vfunc(xs) model= Sequential() model.add(Dense(units=256, input_shape=(1,), activation="tanh")) model.add(Dense(units=256, activation="tanh")) ..a number of layers here model.add(Dense(units=256, activation="tanh")) model.add(Dense(units=1)) model.compile(optimizer="sgd", loss="mse") model.fit(xs, ys, epochs=500, verbose=0) I then generate some test data, which overlays my learning data, but also introduces some new data test_xs = np.arange(-15, 45, 0.01) test_ys = model.predict(test_xs) plt.plot(xs, ys) plt.plot(test_xs, test_ys) Predicted data and learning data looks as follows. The more layers I add, the more curves netw...

In a SVM model, will results be viable when I decrease the test size to 0.06

In a SVM model, will results be viable when I decrease the test size to 0.06 I used support vector machine model for classification using iris data set. I used train test split function to split the data-set into training and testing subsets. when test_size was 0.3 the accuracy was low and then I decreased the size of testing subset to 0.06 and now the accuracy is 1 ie. 100%. obviously, the reason is clear, its because with testing data the amount of noise and fluctuations as decreases. My question is- we want our model to be efficient but what value of test_size is acceptable for that. at what value of test_size will the result be viable. here is some line of code from my program- from sklearn import datasets from sklearn import svm import numpy as np from sklearn import metrics iris = datasets.load_iris() X = iris.data[:, :2] y = iris.target C=1.0 from sklearn.cross_validation import train_test_split x_train, x_test, y_train ,y_test = train_tes...