官术网_书友最值得收藏!

Cleaning up the dataset

After looking at the output, we can see a number of problems:

  • The date is just a string and not a date object
  • From visually inspecting the results, the headings aren't complete or correct

These issues come from the data and we could fix this by altering the data itself. However, in doing this, we could forget the steps we took or misapply them; that is, we can't replicate our results. As with the previous section where we used pipelines to track the transformations we made to a dataset, we will use pandas to apply transformations to the raw data itself.

The pandas.read_csv function has parameters to fix each of these issues, which we can specify when loading the file. We can also change the headings after loading the file, as shown in the following code:

dataset = pd.read_csv(data_filename, parse_dates=["Date"]) dataset.columns
= ["Date", "Start (ET)", "Visitor Team", "VisitorPts",
"Home Team", "HomePts", "OT?", "Score Type", "Notes"]

The results have significantly improved, as we can see if we print out the resulting data frame:

dataset.head()

The output is as follows:

Even in well-compiled data sources such as this one, you need to make some adjustments. Different systems have different nuances, resulting in data files that are not quite compatible with each other. When loading a dataset for the first time, always check the data loaded (even if it's a known format) and also check the data types of the data. In pandas, this can be done with the following code:

print(dataset.dtypes)

Now that we have our dataset in a consistent format, we can compute a baseline, which is an easy way to get a good accuracy on a given problem. Any decent data mining solution should beat this baseline figure.

For a product recommendation system, a good baseline is to simply recommend the most popular product.
For a classification task, it can be to always predict the most frequent task, or alternatively applying a very simple classification algorithm like OneR.

For our dataset, each match has two teams: a home team and a visitor team. An obvious baseline for this task is 50 percent, which is our expected accuracy if we simply guessed a winner at random. In other words, choosing the predicted winning team randomly will (over time) result in an accuracy of around 50 percent. With a little domain knowledge, however, we can use a better baseline for this task, which we will see in the next section.

主站蜘蛛池模板: 重庆市| 宝兴县| 定南县| 平阴县| 鞍山市| 土默特左旗| 通河县| 兴和县| 东明县| 罗平县| 青阳县| 马龙县| 曲阳县| 扬州市| 溆浦县| 富源县| 道真| 砚山县| 喀喇沁旗| 桐庐县| 道孚县| 彰化市| 灌南县| 瑞金市| 长垣县| 灵川县| 宜黄县| 南通市| 诏安县| 定襄县| 介休市| 灵台县| 安平县| 万荣县| 镶黄旗| 永寿县| 延津县| 明水县| 阿图什市| 东乡族自治县| 奎屯市|