sklearn包没有model_selection

sklearn包版本都为0.19.1了 为什么还是没有model_selection

2个回答

sinat_37500899
JackAffleck 都说了版本已经0.19.1,文章里说更新到0.18就可以了,0.19已经没法更新了
接近 2 年之前 回复

你好,我的问题解决了,我用的pycharm,在更新sklearn之后,新建工程选择更新之后的解释器就不报错了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
在sublime里出现ImportError: No module named sklearn.model_selection但是terminal里已经安装
在更新了mac Catalina之后问题不断。。。目前我在terminal里面pip安装了scikit-learn,版本号是0.21.3,但是我的sublime里面却说找不到sklearn model。。我的sublime版本是3.22。我个人感觉是环境配置需要再改改,求大佬指点!
【提问】请教python调用sklearn完成特征工程问题
b_model = pd.read_csv('C:/Users/USER/Desktop/b_model.csv') b_model_skip = b_model.drop(['borrower_index','begin_time','withhold_time_first','num_period_percent', 'f01','f02','f03','f04','f05','f06','f07','f08','f09','f10'],axis=1) b_model_dropnan = b_model_skip.dropna() b_model_dropnan_independentvariable = b_model_dropnan.drop(['target'],axis=1) b_model_dropnan_label = b_model_dropnan.target x, y = b_model_dropnan_independentvariable, b_model_dropnan_label ![图片说明](https://img-ask.csdn.net/upload/201807/06/1530860527_265210.jpg) 这时候,b_model_dropnan_independentvariable 是Dataframe数据框格式,具有列名。 from sklearn.feature_selection import VarianceThreshold sel = VarianceThreshold(threshold=(.8 * (1 - .8))) b_model_dropnan_variancethreshold = sel.fit_transform(b_model_dropnan_independentvariable) 当我使用sklearn移除低方差特征后,b_model_dropnan_variancethreshold 是arrat数组格式,是没有列名的。 ![图片说明](https://img-ask.csdn.net/upload/201807/06/1530860543_404992.jpg) 这种情况下,首先,我确认是可以通过算法建立模型的,但数组没有列名的情况下,我后面如何确认feature importance呢?只确认留下是哪些与target高度相关的变量。 也无法转换为dataframe格式,然后重命名,毕竟特征数量过多,无法一一比对重新命令,而且有的低相关性变量也会变删除,很难进行比对。
通过CountVectorizer和chi2特征提取,进行文本分类,准确率只有0.34正常吗
代码如下: ``` #encoding=utf-8 from sklearn.feature_selection import SelectKBest from sklearn.feature_selection import chi2 from sklearn.datasets import fetch_20newsgroups from sklearn.feature_extraction.text import CountVectorizer from sklearn.naive_bayes import MultinomialNB from sklearn.svm import SVC from sklearn.model_selection import GridSearchCV from sklearn.metrics import accuracy_score,make_scorer from sklearn.metrics import classification_report,accuracy_score import numpy as n categories = ['alt.atheism','talk.religion.misc','comp.graphics','sci.space'] data_train = fetch_20newsgroups(subset='train',categories=categories) data_test = fetch_20newsgroups(subset='test',categories=categories) count = CountVectorizer(stop_words='english',min_df=2) train_feature = count.fit_transform(data_train.data) print train_feature.toarray() chi = SelectKBest(chi2,k=500) train = chi.fit_transform(train_feature,data_train.target) test_feature = count.fit_transform(data_test.data) test = chi.fit_transform(test_feature,data_test.target) # clf = MultinomialNB() # classifier = clf.fit(train,data_train.target) # test_accuracy = classifier.score(test,data_test.target) # print test_accuracy svc = SVC() param_grid = {'kernel':('linear','poly'),'C':[0.1,1]} grid_search = GridSearchCV(svc,param_grid=param_grid,cv=5,scoring=make_scorer(accuracy_score)) grid_search.fit(train,data_train.target) y = grid_search.predict(test) print grid_search.best_estimator_ print 'accuracy',accuracy_score(data_test.target,y) print classification_report(data_test.target,y) ``` 结果: accuracy 0.34885439763488546 precision recall f1-score support 0 0.34 0.39 0.36 319 1 0.42 0.43 0.43 389 2 0.36 0.33 0.34 394 3 0.22 0.20 0.21 251 micro avg 0.35 0.35 0.35 1353 macro avg 0.34 0.34 0.34 1353 weighted avg 0.35 0.35 0.35 1353 求大佬指导一下 哪有问题吗
titanic中随机森林方法报错
错误信息为 File "F:/python项目/titanic.py", line 55, in <module> kf = KFold(titanic.shape[0],n_splits=3,random_state=1) TypeError: __init__() got multiple values for argument 'n_splits' Process finished with exit code 1 代码为: ``` import pandas import numpy as np from sklearn.linear_model import LogisticRegression from sklearn import cross_validation from sklearn.linear_model import LinearRegression from sklearn.model_selection import cross_val_score from sklearn import cross_validation from sklearn.model_selection import KFold from sklearn.ensemble import RandomForestClassifier #导入 titanic = pandas.read_csv("all/train.csv") #print(titanic.head(3)) #print(titanic.describe()) #处理缺失数据 titanic["Age"] = titanic["Age"].fillna(titanic["Age"].median()) #print(titanic.describe()) titanic.loc[titanic["Sex"]=="male","Sex"]=0 titanic.loc[titanic["Sex"]=="female","Sex"]=1 titanic["Embarked"] = titanic["Embarked"].fillna('S') titanic.loc[titanic["Embarked"]=="S","Embarked"]=0 titanic.loc[titanic["Embarked"]=="C","Embarked"]=1 titanic.loc[titanic["Embarked"]=="Q","Embarked"]=2 #print(titanic["Sex"].unique()) #print(titanic["Embarked"].unique()) predictors = ["Pclass","Sex","Age","Sibsp","Parch","Fare","Embarked"] alg = RandomForestClassifier(random_state=1, n_estimators=10,min_samples_split=2,min_samples_leaf=1) kf = KFold(titanic.shape[0],n_splits=3,random_state=1) scores = cross_val_score(alg,titanic[predictors],titanic["Survived"],cv=kf) print(scores.means()) ``` 谢谢各位
用sklearn做线性回归, 但数据normalization后,出来MSE全部为0。
用sklearn在股票价格数据 做线性回归, 但数据normalization后,出来MSE的结果全部为0。别人说是模型出错了, 但奈何自己是python新手,请求各位帮忙指出其中原因,感谢感谢!!!! 数据是这样子的: ![图片说明](https://img-ask.csdn.net/upload/201812/09/1544362511_813119.jpg) 这是不加normalization的, ``` from sklearn.linear_model import LinearRegression from sklearn import cross_validation from sklearn.model_selection import train_test_split from sklearn.preprocessing import Normalizer LinearRegression=LinearRegression() scores = cross_validation.cross_val_score(LinearRegression, X_stock1_train, y_stock1_train, scoring='neg_mean_squared_error', cv=10) print (-scores) print ('Average score for Linear Regression:', np.mean(scores)) ``` 结果看起来还算正常: [ 0.03666889 0.05985924 0.05718805 0.04757506 0.05605501 0.05602068 0.04308263 0.05089644 0.0489978 0.0384472 ] Average score for Linear Regression: -0.0494790998005 ##分割线## normalization处理过的: ``` from sklearn.linear_model import LinearRegression from sklearn import cross_validation transformer=Normalizer().fit(X_stock1_train, y_stock1_train) X_stock1_train=transformer.transform(X_stock1_train) y_stock1_train=transformer.transform(y_stock1_train) LinearRegression=LinearRegression() scores = cross_validation.cross_val_score(LinearRegression, X_stock1_train, y_stock1_train, scoring='neg_mean_squared_error', cv=10) print (-scores) print ('Average score for Linear Regression:', np.mean(scores)) ``` 结果: [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] Average score for Linear Regression: 0.0 别人说是模型出错了, 但奈何自己是python新手,请求各位帮忙指出其中原因,感谢感谢!!!
报错ImportError: cannot import name 'BaseEstimator'
有遇到这个问题的嘛 ![图片说明](https://img-ask.csdn.net/upload/201904/04/1554376729_569223.png) 貌似是sklearn库的问题,我卸了numpy scipy scikt-learn又重装也没得用 网上查不到这个报错”ImportError: cannot import name 'BaseEstimator'“ 代码: from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split def datasets_demo(): #获取并打印数据集 iris = load_iris() print("鸢尾花数据集:\n", iris) print("查看数据集描述:\n", iris["DESCR"]) print("查看特征值名字:\n", iris.feature_names) print("查看特征值名字:\n", iris.data, iris.data.shape) x_train,x_text,y_train,y_text=train_test_split(iris.data,iris.target,text_size=0.2,random_state=22) prinit("训练集特征值:\n",x_train,x_train.shape) 报错: D:\python\python.exe "F:/Administrator/python/begin/day1/machine learning.py" Traceback (most recent call last): File "F:/Administrator/python/begin/day1/machine learning.py", line 1, in <module> from sklearn.datasets import load_iris File "D:\python\lib\site-packages\sklearn\__init__.py", line 64, in <module> from .base import clone File "D:\python\lib\site-packages\sklearn\base.py", line 6, in <module> import copy File "F:\Administrator\python\begin\day1\copy.py", line 1, in <module> from sklearn.datasets import load_iris File "D:\python\lib\site-packages\sklearn\datasets\__init__.py", line 23, in <module> from .twenty_newsgroups import fetch_20newsgroups File "D:\python\lib\site-packages\sklearn\datasets\twenty_newsgroups.py", line 44, in <module> from ..feature_extraction.text import CountVectorizer File "D:\python\lib\site-packages\sklearn\feature_extraction\__init__.py", line 7, in <module> from .dict_vectorizer import DictVectorizer File "D:\python\lib\site-packages\sklearn\feature_extraction\dict_vectorizer.py", line 11, in <module> from ..base import BaseEstimator, TransformerMixin ImportError: cannot import name 'BaseEstimator' 进程已结束,退出代码1
求助:KerasClassifier和GridSearchCV不会用,大佬们帮帮我
我最近在看魏贞元 著的《深度学习,基于Keras的Python实践》,上面有一段代码在我的电脑上会出现异常,大家能帮我看看要怎么修改吗? ``` from sklearn import datasets import numpy as np from keras.models import Sequential from keras.layers import Dense from keras.wrappers.scikit_learn import KerasRegressor from sklearn.model_selection import cross_val_score, KFold, GridSearchCV from sklearn.preprocessing import StandardScaler dataset = datasets.load_boston() x = dataset.data Y = dataset.target seed = 7 np.random.seed(seed) def create_model(units_list=[13], optimizer='adam', init='normal'): model = Sequential() units = units_list[0] model.add(Dense(units, activation='relu', input_dim=13, kernel_initializer=init)) for units in units_list[1:]: model.add(Dense(units, activation='relu', kernel_initializer=init)) model.add(Dense(1, kernel_initializer=init)) model.compile(loss='mean_squared_error', optimizer=optimizer) return model model = KerasRegressor(build_fn=create_model, verbose=0) param_grid = {} param_grid['units_list'] = [[20], [13, 6]] param_grid['optimizer'] = ['rmsprop', 'adam'] param_grid['init'] = ['glorot_uniform', 'normal'] param_grid['epochs'] = [100, 200] param_grid['batch_size'] = [5, 20] scaler = StandardScaler() scaler_x = scaler.fit_transform(x) grid = GridSearchCV(estimator=model, param_grid=param_grid) results = grid.fit(scaler_x, Y) print('Best: %f using %r' % (results.best_score_, results.best_params_)) ``` 这段代码在书的第8章58页。大佬们能帮我看看为什么不能运行吗?谢谢 (我用的keras版本是2.3.1,后端是tensorflow2.1.0。作者用的是keras2.0.8)
运行结果如下:train(generator,discriminator,gan_model,latent_dim) NameError: name 'train' is not defined,请问如何解决
import matplotlib.pyplot as plt from sklearn.model_selection import train_test_split from numpy import hstack from numpy import zeros from numpy import ones from numpy.random import rand from numpy.random import randn from keras.models import Sequential from keras.layers import Dense def define_discriminator(n_inputs=2): model=Sequential() model.add(Dense(25, activation='relu',kernel_initializer='he_uniform',input_dim=n_inputs)) model.add(Dense(1,activation='sigmoid')) model.compile(loss='binary_crossentropy',optimizer='adam', metrics=['accuracy']) return model def define_generator(latent_dim,n_outputs=2): model=Sequential() model.add(Dense(15, activation='relu',kernel_initializer='he_uniform', input_dim=latent_dim)) model.add(Dense(n_outputs,activation='linear')) return model def define_gan(generator,discriminator): discriminator.trainable=False model=Sequential() model.add(generator) model.add(discriminator) model.compile(loss='binary_crossentropy',optimizer='adam') return model def generate_real_samples(n): x1=rand(n)-0.5 x2=x1*x1 x1=x1.reshape(n,1) x2=x2.reshape(n,1) x=hstack((x1,x2)) y=ones((n,1)) return x,y def generate_latent_points(latent_dim,n): x_input=randn(latent_dim*n) x_input=x_input.reshape(n,latent_dim) return x_input def generate_fake_samples(generator,latent_dim,n): x_input=generate_latent_points(latent_dim,n) x=generator.predict(x_input) y=zeros((n,1)) return x,y def summarize_performance(epoch,generator,discriminator,latent_dim,n=100): x_real,y_real=generate_real_samples(n) _,acc_real=discriminator.evaluate(x_real,y_real,verbose=0) x_fake, y_fake = generate_fake_samples(generator,latent_dim,n) _, acc_fake = discriminator.evaluate(x_fake, y_fake, verbose=0) print(epoch,acc_real,acc_fake) plt.scatter(x_real[:,0],x_real[:,1],color='red') plt.scatter(x_fake[:, 0], x_fake[:, 1], color='blue') plt.show() def train(g_model,d_model,gan_model,latent_dim,n_epochs=10000,n_batch=128,n_eval=2000): half_batch=int(n_batch/2) for i in range(n_epochs): x_real,y_real=generate_real_samples(half_batch) x_fake,y_fake=generate_fake_samples(g_model,latent_dim,half_batch) d_model.train_on_batch(x_real,y_real) d_model.train_on_batch(x_fake, y_fake) x_gan=generate_latent_points(latent_dim,n_batch) y_gan=ones((n_batch,1)) gan_model.train_on_batch(x_gan,y_gan) if(i+1)%n_epochs==0: summarize_performance(i,g_model,d_model,latent_dim) latent_dim=5 discriminator=define_discriminator() generator=define_generator(latent_dim) gan_model=define_gan(generator,discriminator) train(generator,discriminator,gan_model,latent_dim) 问题
bad input shape (60000, 2)
本小白在看机器学习实战时,绘制精度、召回率相对阈值的函数图时报了错。 代码如下: ``` from sklearn.datasets import fetch_mldata import matplotlib import matplotlib.pyplot as plt import numpy as np from sklearn.linear_model import SGDClassifier from sklearn.model_selection import StratifiedKFold from sklearn.base import clone from sklearn.model_selection import cross_val_score from sklearn.model_selection import cross_val_predict from sklearn.metrics import confusion_matrix from sklearn.metrics import precision_score,recall_score from sklearn.metrics import f1_score from sklearn.metrics import precision_recall_curve from sklearn.metrics import roc_curve from sklearn.metrics import roc_auc_score #导入部分 mnist = fetch_mldata('MNIST original') X,y = mnist["data"],mnist["target"] #显现部分 some_digit = X[36000] some_digit_image = some_digit.reshape(28,28) plt.imshow(some_digit_image,cmap=matplotlib.cm.binary,interpolation="nearest") plt.axis("off") #plt.show() #训练集和测试集 X_train,X_test,y_train,y_test=X[:60000],X[60000:],y[:60000],y[60000:] shuffle_index = np.random.permutation(60000) X_train,y_train = X_train[shuffle_index],y_train[shuffle_index] #二分分类器 y_train_5 = (y_train == 5) y_test_5 = (y_test == 5) sgd_clf = SGDClassifier(random_state=42) sgd_clf.fit(X_train,y_train_5) predict1 = sgd_clf.predict([some_digit]) print(predict1) #实施交叉验证 skfolds = StratifiedKFold(n_splits=3,random_state=42) for train_index,test_index in skfolds.split(X_train,y_train_5): clone_clf = clone(sgd_clf) X_train_folds = X_train[train_index] y_train_folds = (y_train_5[train_index]) X_test_fold = X_train[test_index] y_test_fold = (y_train_5[test_index]) clone_clf.fit(X_train_folds,y_train_folds) y_pred = clone_clf.predict(X_test_fold) n_correct = sum(y_pred == y_test_fold) print(n_correct/len(y_pred)) #kfold方法 print(cross_val_score(sgd_clf,X_train,y_train_5,cv=3,scoring="accuracy")) y_train_pred = cross_val_predict(sgd_clf,X_train,y_train_5,cv=3) #print(confusion_matrix(y_train_5,y_train_pred)) #print(precision_score(y_train_5,y_pred)) #精度 #print(recall_score(y_train_5,y_train_pred)) #召回率 #print(f1_score(y_train_5,y_pred)) #fi分数 y_scores = sgd_clf.decision_function([some_digit]) print(y_scores) #threshold = 0 #y_some_digit_pred = (y_scores>threshold) #print(y_some_digit_pred) #提高阈值 threshold = 200000 y_some_digit_pred = (y_scores>threshold) print(y_some_digit_pred) #绘制阈值函数图 y_scores = cross_val_predict(sgd_clf,X_train,y_train_5,cv=3,method="decision_function") precisions, recalls, thresholds = precision_recall_curve(y_train_5,y_scores) def plot_precison_recall_vs_threshold(precisions,recalls,thresholds): plt.plot(thresholds,precisions[:-1],"b--",label="Precision") plt.plot(thresholds, recalls[:-1], "g-", label="Recall") plt.xlabel("Threshold") plt.legend(loc="upper left") plt.ylim([0,1]) plot_precison_recall_vs_threshold(precisions,recalls,thresholds) plt.show() ``` 报错信息如下: Traceback (most recent call last): File "F:/python项目/mnist.py", line 77, in <module> precisions, recalls, thresholds = precision_recall_curve(y_train_5,y_scores) File "C:\Users\15701\Anaconda3\lib\site-packages\sklearn\metrics\ranking.py", line 417, in precision_recall_curve sample_weight=sample_weight) File "C:\Users\15701\Anaconda3\lib\site-packages\sklearn\metrics\ranking.py", line 304, in _binary_clf_curve y_score = column_or_1d(y_score) File "C:\Users\15701\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 583, in column_or_1d raise ValueError("bad input shape {0}".format(shape)) ValueError: bad input shape (60000, 2) 不胜感激
请问executablenotfound是什么问题?
如题,今天想用graphviz做一个决策树,结果就报错,我以为是graphviz没安装上,但是我发现没错啊,已经安装成功了,希望诸位大神帮一下忙 代码如下: ``` from sklearn import tree from sklearn.datasets import load_wine from sklearn.model_selection import train_test_split wine=load_wine() import pandas as pd pd.concat([pd.DataFrame(wine.data),pd.DataFrame(wine.target)],axis=1) Xtrain,Xtest,Ytrain,Ytest=train_test_split(wine.data,wine.target,test_size=0.3) clf=tree.DecisionTreeClassifier(criterion='entropy') clf=clf.fit(Xtrain,Ytrain) score=clf.score(Xtest,Ytest) feature_name=['酒精','苹果酸','灰','灰的碱性','镁','总酚','类黄酮','非黄烷类酚类', '花青素','颜色强度','色调','od280/od315稀释葡萄酒','脯氨酸'] import graphviz dot_data=tree.export_graphviz(clf ,feature_names=feature_name ,class_names=['琴酒','雪莉','贝尔摩德'] ,filled=True ,rounded=True ) graph=graphviz.Source(dot_data) graph ```
knn猫狗识别算法中样本为0报错
错误如下: ValueError: With n_samples=0, test_size=0.25 and train_size=None, the resulting train set will be empty. Adjust any of the aforementioned parameters. 代码如下: # import the necessary packages from sklearn.neighbors import KNeighborsClassifier from sklearn.preprocessing import LabelEncoder from sklearn.model_selection import train_test_split from sklearn.metrics import classification_report from pyimagesearch.preprocessing import SimplePreprocessor from pyimagesearch.datasets import SimpleDatasetLoader from imutils import paths import argparse # construct the argument parse and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-d", "--datasets", type=str, default="‪H:\\111\\try1\\pyimagesearch\\datasets\\animals\\", help="path to input dataset") ap.add_argument("-k", "--neighbors", type=int, default=1, help="# of nearest neighbors for classification") ap.add_argument("-j", "--jobs", type=int, default=-1, help="# of jobs for k-NN distance (-1 uses all available cores)") args = vars(ap.parse_args()) # grab the list of images that we’ll be describing print("[INFO] loading images...") imagePaths = list(paths.list_images(args["datasets"])) # initialize the image preprocessor, load the dataset from disk, # and reshape the data matrix sp = SimplePreprocessor.SimplePreprocessor(32, 32) sdl = SimpleDatasetLoader.SimpleDatasetLoader(preprocessors=[sp]) (data, labels) = sdl.load(imagePaths, verbose=500) data = data.reshape((data.shape[0], 3072)) # show some information on memory consumption of the images print("[INFO] features matrix: {:.1f}MB".format( data.nbytes / (1024 * 1000.0))) # encode the labels as integers le = LabelEncoder() labels = le.fit_transform(labels) # partition the data into training and testing splits using 75% of # the data for training and the remaining 25% for testing (trainX, testX, trainY, testY) = train_test_split(data, labels, test_size=0.25, random_state=42) # train and evaluate a k-NN classifier on the raw pixel intensities print("[INFO] evaluating k-NN classifier...") model = KNeighborsClassifier(n_neighbors=args["neighbors"], n_jobs=args["jobs"]) model.fit(trainX, trainY) print(classification_report(testY, model.predict(testX), target_names=le.classes_)) ``` ```
在运行tensorflow MNIST 里的例子时报错
/tensorflow-master/tensorflow/examples/tutorials/mnist$ python fully_connected_feed.py /usr/local/lib/python2.7/dist-packages/sklearn/cross_validation.py:44: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20. "This module will be removed in 0.20.", DeprecationWarning) Traceback (most recent call last): File "fully_connected_feed.py", line 277, in <module> tf.app.run(main=main, argv=[sys.argv[0]] + unparsed) TypeError: run() got an unexpected keyword argument 'argv' 我是从GITHUB上下载的包,代码也没改,运行的fully_connceted_feed.py时报错
机器学习中怎么使用保存的模型进行预测
我使用一个文档中的数据训练了岭回归模型并保存,想通过这个模型来预测另一个文档中的数据(两个文档中的数据只是数量不一样) 预测的文档中有2W+条数据,但是预测结果只有6000+条。 请问各位大神怎么才能使预测结果按每条数据的顺序全部得出来。 本人完全小白,论文想做个机器学习的东西...求各位大神指导 ``` from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler import pandas as pd import joblib as jb def mylinear(): """ 岭回归预测TOC :return: None """ # 获取数据 data = pd.read_csv("./NH25-4.csv") # 删除部分列 data = data.drop(["E_HORZ", "E_VERT", "PR_HORZ", "PR_VERT", "Brittle_Horz%", "Brittle_Vert%", "POR", "DEPTH"], axis=1) # 取出特征值和目标值 y = data["TOC"] x = data.drop(["TOC"], axis=1) # 分割数据集到训练集和测试集 x_train, x_test, y_train, y_test = train_test_split(x, y) # 标准化 std_x = StandardScaler() x_train = std_x.fit_transform(x_train) x_test = std_x.transform(x_test) # 目标值 std_y = StandardScaler() y_train = std_y.fit_transform(y_train.values.reshape(-1, 1)) y_test = std_y.transform(y_test.values.reshape(-1, 1)) # 加载模型 model = jb.load("./test_Ridge.pkl") y_predict = std_y.inverse_transform(model.predict(x_test)) print("保存的模型预测的结果:", y_predict) if __name__ == "__main__": mylinear() ```
用keras搭建BP神经网络对数据集进行回归预测,效果和同学的相比很差,麻烦大神指点。新手小白。。。
数据集是csv文件,一共十三列,十几万行,第十三列是要预测的值。 试过很多种方法(都是百度的),包括更改网络层数、 节点数,学习率……,效果都没什么提升 不知道问题出在哪里,请大神指点。 import numpy as np import keras as ks from keras.models import Sequential from sklearn import preprocessing from sklearn.model_selection import train_test_split from keras.layers import Dense, Activation,Dropout x_yuan = np.loadtxt(open("shaixuandata.csv","rb"),\ usecols=(range(12)),delimiter=",",skiprows=1) x = preprocessing.scale(x_yuan) y = np.loadtxt(open("shaixuandata.csv","rb"),\ usecols=(12),delimiter=",",skiprows=1) x_train, x_test, y_train, y_test = train_test_split(\ x, y, test_size=0.25, random_state=43) model = Sequential() model.add(Dense(units=30, input_dim=12)) model.add(Activation('relu')) model.add(Dropout(0.1)) model.add(Dense(units=1)) model.add(Activation('linear')) ks.callbacks.ReduceLROnPlateau(monitor='val_loss', factor=0.1, \ patience=10, verbose=0, mode='auto', epsilon=0.0001, cooldown=0, min_lr=0) sgd = ks.optimizers.SGD(lr=0.001, clipnorm=1.,decay=1e-6, momentum=0.9) model.compile(optimizer='sgd', loss='mae', metrics=['mae']) model.fit(x_train, y_train, batch_size=30, epochs=3, callbacks=None, \ validation_data=(x_test,y_test), shuffle=True, class_weight=None, \ sample_weight=None, initial_epoch=0) predict = model.predict(x_test) sum = 0 for i in range(len(y_test)): sum = sum+(y_test[i]-predict[i])**2 mse = sum/len(y_test) print(mse) ![训练的结果是这样的,老实说训练结果太差](https://img-ask.csdn.net/upload/201806/27/1530098555_142017.png)
python item2vec的实现问题
``` from gensim.models import Word2Vec import logging import sys reload(sys) sys.setdefaultencoding('utf8') from sklearn.model_selection import train_test_split c = [] def load_sequence(from_path): with open(from_path) as fp: [c.append(line.strip().split(",")) for line in fp] def main(): logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO) load_sequence('E:\\wordpython\\1105\\to666.txt') # 加载语料 c_train,c_text = train_test_split(c,test_size=0.2) model = Word2Vec(c_train, size=20, window=3, min_count=1, workers=1, iter=3, sample=1e-4, negative=20) # 训练skip-gram模型; 默认window=5 test_size = float(len(c_text)) hit = 0.0 for current_pattern in c_text: if len(current_pattern) < 2: test_size -= 1.0 continue # Reduce the current pattern in the test set by removing the last item last_item = current_pattern.pop() # Keep those items in the reduced current pattern, which are also in the models vocabulary items = [it for it in current_pattern if it in model.wv.vocab] if len(items) <= 2: test_size -= 1.0 continue # Predict the most similar items to items prediction = model.most_similar(positive=items,topn=20) # Check if the item that we have removed from the test, last_item, is among # the predicted ones. for predicted_item, score in prediction: if predicted_item == last_item: hit += 1.0 print 'Accuracy like measure: {}'.format(hit / test_size) if __name__ == "__main__": main() ``` No handlers could be found for logger "gensim.models.doc2vec"是什么回事?也没用doc2vec啊
在做kaggle中的titanic为什么报错呢?
小小白在上手titanic,出了问题,求帮忙解答~ 代码如下: ``` import pandas from sklearn.linear_model import LinearRegression from sklearn.model_selection import KFold #导入 titanic = pandas.read_csv("all/train.csv") #print(titanic.head(3)) #print(titanic.describe()) #处理缺失数据 titanic["Age"] = titanic["Age"].fillna(titanic["Age"].median()) #print(titanic.describe()) titanic.loc[titanic["Sex"]=="male","Sex"]=0 titanic.loc[titanic["Sex"]=="female","Sex"]=1 titanic["Embarked"] = titanic["Embarked"].fillna('S') titanic.loc[titanic["Embarked"]=="S","Embarked"]=0 titanic.loc[titanic["Embarked"]=="C","Embarked"]=1 titanic.loc[titanic["Embarked"]=="Q","Embarked"]=2 #print(titanic["Sex"].unique()) #print(titanic["Embarked"].unique()) #KFold predictors = ["Pclass","Sex","SibSp","Parch","Fare","Embareked"] alg = LinearRegression() kf = KFold(titanic.shape[0],n_folds=3,random_state=1) predictions = [] for train, test in kf: train_predictiors = (titanic[predictors].iloc[train,:]) train_target = titanic["Survived"].iloc[train] alg.fit(train_predictiors,train_target) test_prdictions = alg.predict(titanic[predictors].iloc[test,:]) predictions.append(test_prdictions) ``` 错误如下: Traceback (most recent call last): File "F:/python项目/titanic.py", line 20, in <module> kf = KFold(titanic.shape[0],n_folds=3,random_state=1) TypeError: __init__() got an unexpected keyword argument 'n_folds' Process finished with exit code 1 非常感谢~
关于Tensorflow的DNN分类器
用Tensorflow写了一个简易的DNN网络(输入,一个隐层,输出),用作分类,数据集选用的是UCI 的iris数据集 激活函数使用softmax loss函数使用对数似然 以便最后的结果是一个概率解,选概率最大的分类的结果 目前的问题是预测结果出现问题,用测试数据测试显示结果如下 ![图片说明](https://img-ask.csdn.net/upload/201811/27/1543322274_512329.png) 刚刚入门...希望大家指点一下,谢谢辣! ``` #coding:utf-8 import matplotlib.pyplot as plt import tensorflow as tf import numpy as np import pandas as pd from sklearn.model_selection import train_test_split from sklearn.decomposition import PCA from sklearn import preprocessing from sklearn.model_selection import cross_val_score BATCH_SIZE = 30 iris = pd.read_csv('F:\dataset\iris\dataset.data', sep=',', header=None) ''' # 查看导入的数据 print("Dataset Lenght:: ", len(iris)) print("Dataset Shape:: ", iris.shape) print("Dataset:: ") print(iris.head(150)) ''' #将每条数据划分为样本值和标签值 X = iris.values[:, 0:4] Y = iris.values[:, 4] # 整理一下标签数据 # Iris-setosa ---> 0 # Iris-versicolor ---> 1 # Iris-virginica ---> 2 for i in range(len(Y)): if Y[i] == 'Iris-setosa': Y[i] = 0 elif Y[i] == 'Iris-versicolor': Y[i] = 1 elif Y[i] == 'Iris-virginica': Y[i] = 2 # 划分训练集与测试集 X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.3, random_state=10) #对数据集X与Y进行shape整理,让第一个参数为-1表示整理X成n行2列,整理Y成n行1列 X_train = np.vstack(X_train).reshape(-1, 4) Y_train = np.vstack(Y_train).reshape(-1, 1) X_test = np.vstack(X_test).reshape(-1, 4) Y_test = np.vstack(Y_test).reshape(-1, 1) ''' print(X_train) print(Y_train) print(X_test) print(Y_test) ''' #定义神经网络的输入,参数和输出,定义前向传播过程 def get_weight(shape): w = tf.Variable(tf.random_normal(shape), dtype=tf.float32) return w def get_bias(shape): b = tf.Variable(tf.constant(0.01, shape=shape)) return b x = tf.placeholder(tf.float32, shape=(None, 4)) yi = tf.placeholder(tf.float32, shape=(None, 1)) def BP_Model(): w1 = get_weight([4, 10]) # 第一个隐藏层,10个神经元,4个输入 b1 = get_bias([10]) y1 = tf.nn.softmax(tf.matmul(x, w1) + b1) # 注意维度 w2 = get_weight([10, 3]) # 输出层,3个神经元,10个输入 b2 = get_bias([3]) y = tf.nn.softmax(tf.matmul(y1, w2) + b2) return y def train(): # 生成计算图 y = BP_Model() # 定义损失函数 ce = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=y, labels=tf.arg_max(yi, 1)) loss_cem = tf.reduce_mean(ce) # 定义反向传播方法,正则化 train_step = tf.train.AdamOptimizer(0.001).minimize(loss_cem) # 定义保存器 saver = tf.train.Saver(tf.global_variables()) #生成会话 with tf.Session() as sess: init_op = tf.global_variables_initializer() sess.run(init_op) Steps = 5000 for i in range(Steps): start = (i * BATCH_SIZE) % 300 end = start + BATCH_SIZE reslut = sess.run(train_step, feed_dict={x: X_train[start:end], yi: Y_train[start:end]}) if i % 100 == 0: loss_val = sess.run(loss_cem, feed_dict={x: X_train, yi: Y_train}) print("step: ", i, "loss: ", loss_val) print("保存模型: ", saver.save(sess, './model_iris/bp_model.model')) tf.summary.FileWriter("logs/", sess.graph) #train() def prediction(): # 生成计算图 y = BP_Model() # 定义损失函数 ce = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=y, labels=tf.arg_max(yi, 1)) loss_cem = tf.reduce_mean(ce) # 定义保存器 saver = tf.train.Saver(tf.global_variables()) with tf.Session() as sess: saver.restore(sess, './model_iris/bp_model.model') result = sess.run(y, feed_dict={x: X_test}) loss_val = sess.run(loss_cem, feed_dict={x: X_test, yi: Y_test}) print("result :", result) print("loss :", loss_val) result_set = sess.run(tf.argmax(result, axis=1)) print("predict result: ", result_set) print("real result: ", Y_test.reshape(1, -1)) #prediction() ```
tensorflow训练网络报错Invalid argument
##1.问题 程序报错,提示:Invalid argument: You must feed a value for placeholder tensor 'Placeholder_1' with dtype float and shape [?,24] ##2.代码 ``` import time import numpy as np import pandas as pd import tensorflow as tf import matplotlib.pyplot as plt # import dataset input_Dir = 'E:/data/input_H.csv' output_Dir = 'E:/data/output_H.csv' x_data = pd.read_csv(input_Dir, header = None) y_data = pd.read_csv(output_Dir, header = None) x_data = x_data.values y_data = y_data.values x_data = x_data.astype('float32') y_data = y_data.astype('float32') print("DATASET READY") # from sklearn.model_selection import train_test_split x_train, x_test, y_train, y_test = train_test_split(x_data, y_data, test_size=0.2, random_state=1) row, column = x_train.shape row = float(row) # define structure of neural network n_hidden_1 = 250 n_hidden_2 = 128 n_input = 250 n_classes = 24 #initialize parameters x = tf.placeholder(tf.float32, [None, n_input]) y = tf.placeholder(tf.float32, [None, n_classes]) keep_prob = tf.placeholder(tf.float32) stddev = 0.1 weights = { 'w1': tf.Variable(tf.random_normal([n_input, n_hidden_1], stddev=stddev)), 'w2': tf.Variable(tf.random_normal([n_hidden_1, n_hidden_2], stddev=stddev)), 'out': tf.Variable(tf.random_normal([n_hidden_2, n_classes], stddev=stddev)) } biases = { 'b1': tf.Variable(tf.random_normal([n_hidden_1], stddev=stddev)), 'b2': tf.Variable(tf.random_normal([n_hidden_2], stddev=stddev)), 'out': tf.Variable(tf.random_normal([n_classes], stddev=stddev)) } print("NETWORK READY") # forward propagation def multilayer_perceptron(_X, _weights, _biases): layer_1 = tf.nn.leaky_relu(tf.add(tf.matmul(_X, _weights['w1']), _biases['b1'])) layer_2 = tf.nn.leaky_relu(tf.add(tf.matmul(layer_1, _weights['w2']), _biases['b2'])) return (tf.add(tf.matmul(layer_2, _weights['out']), _biases['out'])) # pred = multilayer_perceptron(x, weights, biases) cost = tf.reduce_mean(tf.square(y - pred)) optm = tf.train.GradientDescentOptimizer(learning_rate=0.03).minimize(cost) init = tf.global_variables_initializer() print("FUNCTIONS READY") n_epochs = 100000 batch_size = 512 n_batches = np.int(np.ceil(row / batch_size)) def fetch_batch(epoch, batch_index, batch_size): # 随机获取小批量数据 np.random.seed(epoch * n_batches + batch_index) indices = np.random.randint(row, size = batch_size) return x_train[indices], y_train[indices] iter = 10000 sess = tf.Session() sess.run(tf.global_variables_initializer()) feeds_test = {x: x_test, y: y_test, keep_prob: 1} for epoch in range(n_epochs): # 总共循环次数 for batch_index in range(n_batches): x_batch, y_batch = fetch_batch(epoch, batch_index, batch_size) feeds_train = {x: x_batch, y: y_batch, keep_prob: 1} sess.run(optm, feed_dict=feeds_train) print("EPOCH %d HAS FINISHED" % (epoch)) print("COST %d :" % (epoch)) print(sess.run(cost),feed_dict=feeds_train) print("\n") sess.close() print("FINISHED") ``` ##3.报错信息 Traceback (most recent call last): File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1356, in _do_call return fn(*args) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1341, in _run_fn options, feed_dict, fetch_list, target_list, run_metadata) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1429, in _call_tf_sessionrun run_metadata) tensorflow.python.framework.errors_impl.InvalidArgumentError: 2 root error(s) found. (0) Invalid argument: You must feed a value for placeholder tensor 'Placeholder_1' with dtype float and shape [?,24] [[{{node Placeholder_1}}]] [[Mean/_7]] (1) Invalid argument: You must feed a value for placeholder tensor 'Placeholder_1' with dtype float and shape [?,24] [[{{node Placeholder_1}}]] 0 successful operations. 0 derived errors ignored. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\IPython\core\interactiveshell.py", line 3296, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-2-762bc58e4306>", line 1, in <module> runfile('C:/Users/Administrator/Desktop/main/demo3.py', wdir='C:/Users/Administrator/Desktop/main') File "E:\Program Files\PyCharm 2019.1.3\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile #求问问题出在什么地方?
InvalidArgumentError: Input to reshape is a tensor with 152000 values, but the requested shape requires a multiple of 576
运行无提示,也没有输出数据,求大神帮助! # -*- coding: utf-8 -*- """ Created on Fri Oct 4 10:01:03 2019 @author: xxj """ import numpy as np from sklearn import preprocessing import tensorflow as tf from sklearn.model_selection import train_test_split import matplotlib.pyplot as plt import pandas as pd #读取CSV文件数据 # 从CSV文件中读取数据,返回DataFrame类型的数据集合。 def zc_func_read_csv(): zc_var_dataframe = pd.read_csv("highway.csv", sep=",") # 打乱数据集合的顺序。有时候数据文件有可能是根据某种顺序排列的,会影响到我们对数据的处理。 zc_var_dataframe = zc_var_dataframe.reindex(np.random.permutation(zc_var_dataframe.index)) return zc_var_dataframe # 预处理特征值 def preprocess_features(highway): processed_features = highway[ ["line1","line2","line3","line4","line5", "brige1","brige2","brige3","brige4","brige5", "tunnel1","tunnel2","tunnel3","tunnel4","tunnel5", "inter1","inter2","inter3","inter4","inter5", "econmic1","econmic2","econmic3","econmic4","econmic5"] ] return processed_features # 预处理标签 highway=zc_func_read_csv() x= preprocess_features(highway) outtarget=np.array(pd.read_csv("highway1.csv")) y=np.array(outtarget[:,[0]]) print('##################################################################') # 随机挑选 train_x_disorder, test_x_disorder, train_y_disorder, test_y_disorder = train_test_split(x, y,train_size=0.8, random_state=33) #数据标准化 ss_x = preprocessing.StandardScaler() train_x_disorder = ss_x.fit_transform(train_x_disorder) test_x_disorder = ss_x.transform(test_x_disorder) ss_y = preprocessing.StandardScaler() train_y_disorder = ss_y.fit_transform(train_y_disorder.reshape(-1, 1)) test_y_disorder=ss_y.transform(test_y_disorder.reshape(-1, 1)) #变厚矩阵 def weight_variable(shape): initial = tf.truncated_normal(shape, stddev=0.1) return tf.Variable(initial) #偏置 def bias_variable(shape): initial = tf.constant(0.1, shape=shape) return tf.Variable(initial) #卷积处理 变厚过程 def conv2d(x, W): # stride [1, x_movement, y_movement, 1] x_movement、y_movement就是步长 # Must have strides[0] = strides[3] = 1 padding='SAME'表示卷积后长宽不变 return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME') #pool 长宽缩小一倍 def max_pool_2x2(x): # stride [1, x_movement, y_movement, 1] return tf.nn.max_pool(x, ksize=[1,2,2,1], strides=[1,2,2,1], padding='SAME') # define placeholder for inputs to network xs = tf.placeholder(tf.float32, [None, 25]) #原始数据的维度:25 ys = tf.placeholder(tf.float32, [None, 1])#输出数据为维度:1 keep_prob = tf.placeholder(tf.float32)#dropout的比例 x_image = tf.reshape(xs, [-1, 5, 5, 1])#原始数据25变成二维图片5*5 ## conv1 layer ##第一卷积层 W_conv1 = weight_variable([2,2, 1,32]) # patch 2x2, in size 1, out size 32,每个像素变成32个像素,就是变厚的过程 b_conv1 = bias_variable([32]) h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1) # output size 2x2x32,长宽不变,高度为32的三维图像 #h_pool1 = max_pool_2x2(h_conv1) # output size 2x2x32 长宽缩小一倍 ## conv2 layer ##第二卷积层 W_conv2 = weight_variable([2,2, 32, 64]) # patch 2x2, in size 32, out size 64 b_conv2 = bias_variable([64]) h_conv2 = tf.nn.relu(conv2d(h_conv1, W_conv2) + b_conv2) #输入第一层的处理结果 输出shape 4*4*64 ## fc1 layer ## full connection 全连接层 W_fc1 = weight_variable([3*3*64, 512])#4x4 ,高度为64的三维图片,然后把它拉成512长的一维数组 b_fc1 = bias_variable([512]) h_pool2_flat = tf.reshape(h_conv2, [-1, 3*3*64])#把3*3,高度为64的三维图片拉成一维数组 降维处理 h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1) h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)#把数组中扔掉比例为keep_prob的元素 ## fc2 layer ## full connection W_fc2 = weight_variable([512, 1])#512长的一维数组压缩为长度为1的数组 b_fc2 = bias_variable([1])#偏置 #最后的计算结果 prediction = tf.matmul(h_fc1_drop, W_fc2) + b_fc2 #prediction = tf.nn.relu(tf.matmul(h_fc1_drop, W_fc2) + b_fc2) # 计算 predition与y 差距 所用方法很简单就是用 suare()平方,sum()求和,mean()平均值 cross_entropy = tf.reduce_mean(tf.reduce_sum(tf.square(ys - prediction), reduction_indices=[1])) # 0.01学习效率,minimize(loss)减小loss误差 train_step = tf.train.AdamOptimizer(0.01).minimize(cross_entropy) sess = tf.Session() # important step # tf.initialize_all_variables() no long valid from # 2017-03-02 if using tensorflow >= 0.12 sess.run(tf.global_variables_initializer()) #训练500次 for i in range(100): sess.run(train_step, feed_dict={xs: train_x_disorder, ys: train_y_disorder, keep_prob: 0.7}) print(i,'误差=',sess.run(cross_entropy, feed_dict={xs: train_x_disorder, ys: train_y_disorder, keep_prob: 1.0})) # 输出loss值 # 可视化 prediction_value = sess.run(prediction, feed_dict={xs: test_x_disorder, ys: test_y_disorder, keep_prob: 1.0}) ###画图########################################################################### fig = plt.figure(figsize=(20, 3)) # dpi参数指定绘图对象的分辨率,即每英寸多少个像素,缺省值为80 axes = fig.add_subplot(1, 1, 1) line1,=axes.plot(range(len(prediction_value)), prediction_value, 'b--',label='cnn',linewidth=2) #line2,=axes.plot(range(len(gbr_pridict)), gbr_pridict, 'r--',label='优选参数') line3,=axes.plot(range(len(test_y_disorder)), test_y_disorder, 'g',label='实际') axes.grid() fig.tight_layout() #plt.legend(handles=[line1, line2,line3]) plt.legend(handles=[line1, line3]) plt.title('卷积神经网络') plt.show()
终于明白阿里百度这样的大公司,为什么面试经常拿ThreadLocal考验求职者了
点击上面↑「爱开发」关注我们每晚10点,捕获技术思考和创业资源洞察什么是ThreadLocalThreadLocal是一个本地线程副本变量工具类,各个线程都拥有一份线程私有的数
win10系统安装教程(U盘PE+UEFI安装)
一、准备工作 u盘,电脑一台,win10原版镜像(msdn官网) 二、下载wepe工具箱  极力推荐微pe(微pe官方下载) 下载64位的win10 pe,使用工具箱制作启动U盘打开软件,   选择安装到U盘(按照操作无需更改) 三、重启进入pe系统   1、关机后,将U盘插入电脑 2、按下电源后,按住F12进入启动项选择(技嘉主板是F12)     选择需要启
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过
《奇巧淫技》系列-python!!每天早上八点自动发送天气预报邮件到QQ邮箱
将代码部署服务器,每日早上定时获取到天气数据,并发送到邮箱。 也可以说是一个小人工智障。 思路可以运用在不同地方,主要介绍的是思路。
Nginx 软件层面加强Nginx性能优化的面试问答和解决方案
Nginx 软件层面加强Nginx性能优化的面试问答和解决方案 去年我去爱卡汽车面试PHP,一轮和二轮面的都不错,在三轮面到Nginx的时候很多问题当时不知道怎么回答,确实没有深入学习过,花了一段时间的学习,终于能解答Nginx高性能优化的问题了,10月24号为了获得程序员勋章,发布了半个优化笔记,浏览到了1000+,受到这个鼓舞,我抽时间在仔细整理下关于Nginx性能优化的问题,我们从软件说起。...
【管理系统课程设计】美少女手把手教你后台管理
【文章后台管理系统】URL设计与建模分析+项目源码+运行界面 栏目管理、文章列表、用户管理、角色管理、权限管理模块(文章最后附有源码) 1. 这是一个什么系统? 1.1 学习后台管理系统的原因 随着时代的变迁,现如今各大云服务平台横空出世,市面上有许多如学生信息系统、图书阅读系统、停车场管理系统等的管理系统,而本人家里就有人在用烟草销售系统,直接在网上完成挑选、购买与提交收货点,方便又快捷。 试想,若没有烟草销售系统,本人家人想要购买烟草,还要独自前往药...
11月19日科技资讯|华为明日发布鸿蒙整体战略;京东宣告全面向技术转型;Kotlin 1.3.60 发布
「极客头条」—— 技术人员的新闻圈! CSDN 的读者朋友们早上好哇,「极客头条」来啦,快来看今天都有哪些值得我们技术人关注的重要新闻吧。扫描上方二维码进入 CSDN App 可以收听御姐萌妹 Style 的人工版音频哟。 一分钟速览新闻点! 6G 专家组成员:速率是 5G 的 10 至 100 倍,预计 2030 年商用 雷军:很多人多次劝我放弃WPS,能坚持下来并不是纯粹的商业决定 ...
C语言魔塔游戏
很早就很想写这个,今天终于写完了。 游戏截图: 编译环境: VS2017 游戏需要一些图片,如果有想要的或者对游戏有什么看法的可以加我的QQ 2985486630 讨论,如果暂时没有回应,可以在博客下方留言,到时候我会看到。 下面我来介绍一下游戏的主要功能和实现方式 首先是玩家的定义,使用结构体,这个名字是可以自己改变的 struct gamerole { char n
化繁为简 - 腾讯计费高一致TDXA的实践之路
导语:腾讯计费是孵化于支撑腾讯内部业务千亿级营收的互联网计费平台,在如此庞大的业务体量下,腾讯计费要支撑业务的快速增长,同时还要保证每笔交易不错账。采用最终一致性或离线补...
Python爬虫爬取淘宝,京东商品信息
小编是一个理科生,不善长说一些废话。简单介绍下原理然后直接上代码。 使用的工具(Python+pycharm2019.3+selenium+xpath+chromedriver)其中要使用pycharm也可以私聊我selenium是一个框架可以通过pip下载 pip install selenium -i https://pypi.tuna.tsinghua.edu.cn/simple/ 
Java学习笔记(七十二)—— Cookie
概述 会话技术: 会话:一次会话中包含多次请求和响应 一次会话:浏览器第一次给服务器发送资源请求,会话建立,直到有一方断开为止 功能:在一次会话的范围内的多次请求间,共享数据 方式: 客户端会话技术:Cookie,把数据存储到客户端 服务器端会话技术:Session,把数据存储到服务器端 Cookie 概念:客户端会话技术,将数据存储到客户端 快速入门: 使用步骤: 创建C
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
Java工作4年来应聘要16K最后没要,细节如下。。。
前奏: 今天2B哥和大家分享一位前几天面试的一位应聘者,工作4年26岁,统招本科。 以下就是他的简历和面试情况。 基本情况: 专业技能: 1、&nbsp;熟悉Sping了解SpringMVC、SpringBoot、Mybatis等框架、了解SpringCloud微服务 2、&nbsp;熟悉常用项目管理工具:SVN、GIT、MAVEN、Jenkins 3、&nbsp;熟悉Nginx、tomca
2020年,冯唐49岁:我给20、30岁IT职场年轻人的建议
点击“技术领导力”关注∆  每天早上8:30推送 作者| Mr.K   编辑| Emma 来源| 技术领导力(ID:jishulingdaoli) 前天的推文《冯唐:职场人35岁以后,方法论比经验重要》,收到了不少读者的反馈,觉得挺受启发。其实,冯唐写了不少关于职场方面的文章,都挺不错的。可惜大家只记住了“春风十里不如你”、“如何避免成为油腻腻的中年人”等不那么正经的文章。 本文整理了冯
程序员该看的几部电影
##1、骇客帝国(1999) 概念:在线/离线,递归,循环,矩阵等 剧情简介: 不久的将来,网络黑客尼奥对这个看似正常的现实世界产生了怀疑。 他结识了黑客崔妮蒂,并见到了黑客组织的首领墨菲斯。 墨菲斯告诉他,现实世界其实是由一个名叫“母体”的计算机人工智能系统控制,人们就像他们饲养的动物,没有自由和思想,而尼奥就是能够拯救人类的救世主。 可是,救赎之路从来都不会一帆风顺,到底哪里才是真实的世界?
作为一个程序员,CPU的这些硬核知识你必须会!
CPU对每个程序员来说,是个既熟悉又陌生的东西? 如果你只知道CPU是中央处理器的话,那可能对你并没有什么用,那么作为程序员的我们,必须要搞懂的就是CPU这家伙是如何运行的,尤其要搞懂它里面的寄存器是怎么一回事,因为这将让你从底层明白程序的运行机制。 随我一起,来好好认识下CPU这货吧 把CPU掰开来看 对于CPU来说,我们首先就要搞明白它是怎么回事,也就是它的内部构造,当然,CPU那么牛的一个东
@程序员,如何花式构建线程?
作者 |曾建责编 | 郭芮出品 | CSDN(ID:CSDNnews)在项目和业务的开发中,我们难免要经常使用线程来进行业务处理,使用线程可以保证我们的业务在相互处理之间可以保证原子性...
破14亿,Python分析我国存在哪些人口危机!
2020年1月17日,国家统计局发布了2019年国民经济报告,报告中指出我国人口突破14亿。 猪哥的朋友圈被14亿人口刷屏,但是很多人并没有看到我国复杂的人口问题:老龄化、男女比例失衡、生育率下降、人口红利下降等。 今天我们就来分析一下我们国家的人口数据吧! 一、背景 1.人口突破14亿 2020年1月17日,国家统计局发布了 2019年国民经济报告 ,报告中指出:年末中国大陆总人口(包括31个
强烈推荐10本程序员在家读的书
很遗憾,这个鼠年春节注定是刻骨铭心的,新型冠状病毒让每个人的神经都是紧绷的。那些处在武汉的白衣天使们,尤其值得我们的尊敬。而我们这些窝在家里的程序员,能不外出就不外出,就是对社会做出的最大的贡献。 有些读者私下问我,窝了几天,有点颓丧,能否推荐几本书在家里看看。我花了一天的时间,挑选了 10 本我最喜欢的书,你可以挑选感兴趣的来读一读。读书不仅可以平复恐惧的压力,还可以对未来充满希望,毕竟苦难终
Linux自学篇——linux命令英文全称及解释
man: Manual 意思是手册,可以用这个命令查询其他命令的用法。 pwd:Print working directory 显示当前目录 su:Swith user 切换用户,切换到root用户 cd:Change directory 切换目录 ls:List files 列出目录下的文件 ps:Process Status 进程状态 mk
Python实战:抓肺炎疫情实时数据,画2019-nCoV疫情地图
文章目录1. 前言2. 数据下载3. 数据处理4. 数据可视化 1. 前言 今天,群里白垩老师问如何用python画武汉肺炎疫情地图。白垩老师是研究海洋生态与地球生物的学者,国家重点实验室成员,于不惑之年学习python,实为我等学习楷模。先前我并没有关注武汉肺炎的具体数据,也没有画过类似的数据分布图。于是就拿了两个小时,专门研究了一下,遂成此文。 2月6日追记:本文发布后,腾讯的数据源多次变更u
智力题(程序员面试经典)
NO.1  有20瓶药丸,其中19瓶装有1克/粒的药丸,余下一瓶装有1.1克/粒的药丸。给你一台称重精准的天平,怎么找出比较重的那瓶药丸?天平只能用一次。 解法 有时候,严格的限制条件有可能反倒是解题的线索。在这个问题中,限制条件是天平只能用一次。 因为天平只能用一次,我们也得以知道一个有趣的事实:一次必须同时称很多药丸,其实更准确地说,是必须从19瓶拿出药丸进行称重。否则,如果跳过两瓶或更多瓶药
在家远程办公效率低?那你一定要收好这个「在家办公」神器!
相信大家都已经收到国务院延长春节假期的消息,接下来,在家远程办公可能将会持续一段时间。 但是问题来了。远程办公不是人在电脑前就当坐班了,相反,对于沟通效率,文件协作,以及信息安全都有着极高的要求。有着非常多的挑战,比如: 1在异地互相不见面的会议上,如何提高沟通效率? 2文件之间的来往反馈如何做到及时性?如何保证信息安全? 3如何规划安排每天工作,以及如何进行成果验收? ......
作为一个程序员,内存和磁盘的这些事情,你不得不知道啊!!!
截止目前,我已经分享了如下几篇文章: 一个程序在计算机中是如何运行的?超级干货!!! 作为一个程序员,CPU的这些硬核知识你必须会! 作为一个程序员,内存的这些硬核知识你必须懂! 这些知识可以说是我们之前都不太重视的基础知识,可能大家在上大学的时候都学习过了,但是嘞,当时由于老师讲解的没那么有趣,又加上这些知识本身就比较枯燥,所以嘞,大家当初几乎等于没学。 再说啦,学习这些,也看不出来有什么用啊!
2020年的1月,我辞掉了我的第一份工作
其实,这篇文章,我应该早点写的,毕竟现在已经2月份了。不过一些其它原因,或者是我的惰性、还有一些迷茫的念头,让自己迟迟没有试着写一点东西,记录下,或者说是总结下自己前3年的工作上的经历、学习的过程。 我自己知道的,在写自己的博客方面,我的文笔很一般,非技术类的文章不想去写;另外我又是一个还比较热衷于技术的人,而平常复杂一点的东西,如果想写文章写的清楚点,是需要足够...
别低估自己的直觉,也别高估自己的智商
所有群全部吵翻天,朋友圈全部沦陷,公众号疯狂转发。这两周没怎么发原创,只发新闻,可能有人注意到了。我不是懒,是文章写了却没发,因为大家的关注力始终在这次的疫情上面,发了也没人看。当然,我...
Java坑人面试题系列: 包装类(中级难度)
Java Magazine上面有一个专门坑人的面试题系列: https://blogs.oracle.com/javamagazine/quiz-2。 这些问题的设计宗旨,主要是测试面试者对Java语言的了解程度,而不是为了用弯弯绕绕的手段把面试者搞蒙。 如果你看过往期的问题,就会发现每一个都不简单。 这些试题模拟了认证考试中的一些难题。 而 “中级(intermediate)” 和 “高级(ad
Spring Boot 2.x基础教程:使用JdbcTemplate访问MySQL数据库
在第2章节中,我们介绍了如何通过Spring Boot来实现HTTP接口,以及围绕HTTP接口相关的单元测试、文档生成等实用技能。但是,这些内容还不足以帮助我们构建一个动态应用的服务端程序。不论我们是要做App、小程序、还是传统的Web站点,对于用户的信息、相关业务的内容,通常都需要对其进行存储,而不是像第2章节中那样,把用户信息存储在内存中(重启就丢了!)。 对于信息的存储,现在已经有非常非常多...
基于Python的人脸自动戴口罩系统
目录 1、项目背景 2、页面设计 3、器官识别 4、退出系统 1、项目背景 2019年新型冠状病毒感染的肺炎疫情发生以来,牵动人心,举国哀痛,口罩、酒精、消毒液奇货可居。 抢不到口罩,怎么办?作为技术人今天分享如何使用Python实现自动戴口罩系统,来安慰自己,系统效果如下所示: 本系统的实现原理是借助 Dlib模块的Landmark人脸68个关键点检测库轻松识别出人脸五官
这个世界上人真的分三六九等,你信吗?
偶然间,在知乎上看到一个问题 一时间,勾起了我深深的回忆。 以前在厂里打过两次工,做过家教,干过辅导班,做过中介。零下几度的晚上,贴过广告,满脸、满手地长冻疮。 再回首那段岁月,虽然苦,但让我学会了坚持和忍耐。让我明白了,在这个世界上,无论环境多么的恶劣,只要心存希望,星星之火,亦可燎原。 下文是原回答,希望能对你能有所启发。 如果我说,这个世界上人真的分三六九等,...
相关热词 c# 压缩图片好麻烦 c#计算数组中的平均值 c#获取路由参数 c#日期精确到分钟 c#自定义异常必须继承 c#查表并返回值 c# 动态 表达式树 c# 监控方法耗时 c# listbox c#chart显示滚动条
立即提问